148 4. 3D Math for Games
The dot product can also be used to fi nd the height of a point above or
below a plane (which might be useful when writing a moon-landing game for
example). We can defi ne a plane with two vector quantities: a point Q lying
anywhere on the plane, and a unit vector n that is perpendicular (i.e., normal)
to the plane. To fi nd the height h of a point P above the plane, we fi rst calculate
a vector from any point on the plane (Q will do nicely) to the point in ques-
tion P. So we have v = P – Q. The dot product of vector v with the unit-length
normal vector n is just the projection of v onto the line defi ned by n. But that
is exactly the height we’re looking for. Therefore, h = v ⋅ n = (P – Q) ⋅ n. This
is illustrated in Figure 4.12.
4.2.4.8. Cross Product
The cross product (also known as the outer product or vector product) of two vec-
tors yields another vector that is perpendicular to the two vectors being multi-
plied, as shown in Figure 4.13. The cross product operation is only defi ned in
three dimensions:
Magnitude of the Cross Product
The magnitude of the cross product vector is the product of the magnitudes of
the two vectors and the sine of the angle between them. (This is similar to the
defi nition of the dot product, but it replaces the cosine with the sine.)
The magnitude of the cross product is equal to the area of the par-
allelogram whose sides are a and b, as shown in Figure 4.14. Since a triangle
is one-half of a parallelogram, the area of a triangle whose vertices are speci-
fi ed by the position vectors V 1 , V 2 , and V 3 can be calculated as one-half of the
magnitude of the cross product of any two of its sides:
a×b
a b
Figure 4.13. The cross
product of vectors a
and b (right-handed).
V 2
V 1
V 3
a= (V 2 – V 1 )
b= (V 3 – V 1 )
|a×b|
Figure 4.14. Area of a parallelogram expressed as the magnitude of a cross product.
[( ), ( ), ( )]
( ) ( ) ( ).
yz zy zx xz xy yx
yz zy zx xz xy yx
ab ab ab ab ab ab
ab ab ab ab ab ab
=−
=−
ab
i
− −
+−jk+−
×
triangle^12131
A = −×− 2 (VV VV) ( ).
a b ab×= sin( ) .θ
ab×