The cross product only works in 3D. It takes two vectors as input v1 and v2,
and returns a vector c. The
returned vector will be perpendicular to both the input vectors. The length of the vector is
equal to the product of the lengths of the input vectors and the sine of the angle between them.
So, if the two input vectors are parallel, the length of the output vector will be zero.
Calculating the Cross Product
Define two input vectors, Vector1 (x1, y1, z1) and Vector2 (x2, y2, z2), and one output vector, OutVect(ox, oy, oz).
The components of OutVect are calculated as follows:
ox = (y1 * z2) - (y2 * z1)
oy = (z1 * x2) - (z2 * x1)
oz = (x1 * y2) - (x2 * y1)
Using the Cross Product
Frequently, in 3D graphics, it is necessary to calculate the normal vector to a polygon.
This is achieved by considering two of the edges of the polygon as vectors, and then calculating
their cross product.
Note: It is very important to get them the right way round. Swapping them, will negate the
output vector.