Game Development Reference
In-Depth Information
Now that the cross product has been covered conceptually, let's look at how it is
calculated:
Remembering how to calculate the cross product just from the preceding formula
is difficult. Luckily, there is a mnemonic to help us remember: “xyzzy.” The way
themnemonic worksisittells ustheorderofthesubscripts forthefirstcomponent
of the cross product:
If you can remember the base equation is
c
=
a
·
b
-
a
·
b
, “xyzzy” tells you which
subscript to use for each term. Once you have the first line, you can figure out
c
y
and
c
z
by rotating the subscripts in the following manner:
x → y → z → x
. This
will then give you the next two lines of the cross product:
Aswiththedotproduct,thereisaspecialcasetowatchoutfor.Ifthecrossproduct
returns a vector where all three components are 0, this means that the two input
vectors are
collinear
, or they lie on the same line. Two collinear vectors cannot
form a plane, and because of that there is no normal for the cross product to return.
Because a triangle is guaranteed to always be on a single plane, we can use the
cross product to determine the vector that's perpendicular to the triangle. This per-
pendicularvectorisknownasthe
normal
ofthetriangle.
Figure3.9
showstriangle
ABC. In order to calculate the normal, we first must construct vectors from A to B
and from A to C. Then if we take the cross product between these two vectors, in a
right-handed coordinate system we would get a vector going into the page, which
corresponds to the direction of the normal.