Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compute the cross-product?

I have the following piece of pseudo-C/Java/C# code:

int a[]= { 30, 20 };
int b[] = { 40, 50 };
int c[] = {12, 12};

How do I compute the cross-product ABxAC?

like image 421
SyntaxT3rr0r Avatar asked Mar 28 '10 13:03

SyntaxT3rr0r


People also ask

How is the cross product calculated?

We can calculate the Cross Product this way: So the length is: the length of a times the length of b times the sine of the angle between a and b, Then we multiply by the vector n so it heads in the correct direction (at right angles to both a and b).

How do you do cross product examples?

Example 2. Calculate the area of the parallelogram spanned by the vectors a=(3,−3,1) and b=(4,9,2). Solution: The area is ∥a×b∥. Using the above expression for the cross product, we find that the area is √152+22+392=5√70.

What is the formula for finding the cross product of two vectors?

The magnitude of the resultant vector is given by the area of the parallelogram between them and its direction can be determined by the right-hand thumb rule. a × b = c, where c is the cross product of the two vectors a and b.


1 Answers

The solution that was given to you in your last question basically adds a Z=0 for all your points. Over the so extended vectors you calculate your cross product. Geometrically the cross product produces a vector that is orthogonal to the two vectors used for the calculation, as both of your vectors lie in the XY plane the result will only have a Z component. The Sign of that z component denotes wether that vector is looking up or down on the XY plane. That sign is dependend on AB being in clockwise or counter clockwise order from each other. That in turn means that the sign of z component shows you if the point you are looking at lies to the left or the right of the line that is on AB.

So with the crossproduct of two vectors A and B being the vector

AxB = (AyBz − AzBy, AzBx − AxBz, AxBy − AyBx)

with Az and Bz being zero you are left with the third component of that vector

AxBy - AyBx

With A being the vector from point a to b, and B being the vector from point a to c means

Ax = (b[x]-a[x])
Ay = (b[y]-a[y])
Bx = (c[x]-a[x])
By = (c[y]-a[y])

giving

AxBy - AyBx = (b[x]-a[x])*(c[y]-a[y])-(b[y]-a[y])*(c[x]-a[x])

which is a scalar, the sign of that scalar will tell you wether point c lies to the left or right of vector ab

Aternatively you can look at stack overflow or gamedev

like image 121
Harald Scheirich Avatar answered Oct 04 '22 10:10

Harald Scheirich