how to generate random isotropic vectors using R?

How do I find the cross product of two vectors in C++ using a function? The two vectors are two 1-D arrays of a class.

  • What i mean by vector here is a 1-d array of size length 3(not the vector container in CPP). Means float a[3],b[3],c[3]; Now suppose we want to store cross product of a and b into array c, how will we do it using a function? The function arguments (inputs) are a[3],b[3] and it should return (output) array c[3]. Can we have return value as an array?

  • Answer:

    No, you cannot return an array. However, you can make a function that a reference to 3 arrays. The function would make three assignments. A function that accepts a single array of 5 ints would look like this: void cool( int (&runnings) [5]) Let's assume the arguments are arrays called a and b, and the output (also the last parameter to the function) is called c. The three equations would look similar to: c[0] = a[1] x b[2] - a[2] x b[1] I can't remember the exact order but every resultant component is the difference between the products of each of the two other components. Sounds fancy, but I'm sure you get what I mean. You could consider making your own vector class which will allow you to return that from a function. Also would result in clearer to understand code. Good luck.

Gregory Currie at Quora Visit the source

Was this solution helpful to you?

Other answers

I used class for doing this vectorsHere v1 and v2 were two vectors provided by user and cross_p is the resultant vector void crossproduct(vector v1,vector v2,vector cross_p){ cross_p.i = (v1.j*v2.k) - (v1.k*v2.j); cross_p.j = -((v1.i*v2.k) - (v1.k*v2.i)); cross_p.k = (v1.i*v2.j) - (v1.j*v2.i); cout<<"crossproduct = "<<cross_p.i<<"i"<<cross_p.j<<"j"<<cross_p.k<<"k"<<endl;}

Chinmay Shah

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.