Game Development Reference
Figure 1.3. Projection of one vector onto another.
1.2.3 Dot Product
The dot product of two vectors a and b is defined as
where θ is the angle between a and b .
For two vectors using a standard Euclidean basis, this can be represented as
a · b = a x b x + a y b y + a z b z .
There are two uses of this that are of particular interest to game physics de-
velopers. First of all, it can be used to do simple tests of the angle between two
vectors. If a
b > 0,then θ<π/ 2;if a
b < 0,then θ>π/ 2;andif a
then θ = π/ 2. In the latter case, we also say that the two vectors are orthogonal .
The other main use of the dot product is for projecting one vector onto another.
If we have two vectors a and b , we can break a into two pieces a || and a ⊥ such
that a || + a ⊥ = a and a || points along the same direction as, or is parallel to, b
(see Figure 1.3 ). The vector a ||
is also known as the scalar projection of a onto b .
cos θ ,whichwe
can see from Figure 1.3 is the length of the projection of a onto b . The projected
vector itself can be computed as
From Equation (1.1), if
b is simply
a || =( a · b ) b .
The remaining, or orthogonal portion of a can be computed as
a ⊥ = a
a || .
1.2.4 Cross Product
The cross product of two vectors a and b is defined as
b =( a y b z −
a z b y ,a z b x −
a x b z ,a x b y −
a y b x ) .