Using the cross product via two vectors, a third vector is calculated. There is a single plane that contains both vectors and so the third vector is the normal to that plane or perpendicular to the plane. Since the cross product returns a normal to a plane, it only works in 3D, however, it can work with 2D vectors after they have been converted into 3D vectors by adding a zeroed z component.
The formula for the cross product is simply Vector C = Vector A * Vector B
However, this gets extended to
Vector C = (Vector A.y * Vector B.z - Vector A.z * Vector B.y, Vector A.z * Vector B.x - Vector A.x * Vector B.z, Vector A.x * Vector B.y - Vector A.y * Vector B.x)
This can be hard to remember but there is a mnemonic that reminds you of the order for the subscipts for the x component of the cross product vector, which is "xyzzy". Combine this with the base equation of c = a*b - a*b and you have the first component.
Vector C.x = Vector A.y * Vector B.z - Vector A.z * Vector B.y
You can figure out the y and z components of the cross product vector by rotating the subscripts in the following manner: x -> y -> z -> x
Vector C.y = Vector A.z * Vector B.x - Vector A.x * Vector B.z
Vector C.z = Vector A.x * Vector B.y - Vector A.y * Vector B.x
It should also be noted that the cross product is anti commutatuve, so Vector A * Vector B = -Vector B * Vector A. Another note is that if the cross product returns a vector where all three components have a value of 0 then both input vectors are collinear, which means they lie on the same line. This means a plane cannot be formed and so there is no normal for the cross product to return.
Special Usage
Since a triangle is always on a single plane, we can calculate its normal by coverting two sides of the triange to vectors, then using those vectors and the cross product we can calculate the normal. If we only care about the direction and not the magnitude of the vector then we can normalise the vector afterwards.
No comments:
Post a Comment