Game Development Reference
In-Depth Information
argument that the projection of a onto b has the same length as the pro-
jection of b onto a . Consider Figure 2.21. The two triangles have equal
interior angles and thus are similar. Since a and b are corresponding sides
and have the same length, the two triangles are reflections of each other.
Figure 2.21
Dot product is commutative
We've already shown how scaling either vector will scale the dot prod-
uct proportionally, so this result applies for a and b with arbitrary length.
Furthermore, this geometric fact is also trivially verified by using the for-
mula, which does not depend on the assumption that the vectors have equal
length. Using two dimensions as our example this time,
a b = a x b x + a y b y = b x a x + b y a y = b a .
Dot product is
commutative
The next important property of the dot product is that it distributes
over addition and subtraction, just like scalar multiplication. This time
let's do the algebra before the geometry. When we say that the dot product
“distributes,” that means that if one of the operands to the dot product
is a sum, then we can take the dot product of the pieces individually, and
then take their sum. Switching back to three dimensions for our example,
2
3
2
3
a x
a y
a z
b x + c x
b y + c y
b z + c z
Dot product distributes
over addition and
subtraction
4
5
4
5
a ( b + c ) =
= a x (b x + c x ) + a y (b y + c y ) + a z (b z + c z )
= a x b x + a x c x + a y b y + a y c y + a z b z + a z c z
= (a x b x + a y b y + a z b z ) + (a x c x + a y c y + a z c z )
= a b + a c .
By replacing c with − c , it's clear that the dot product distributes over
vector subtraction just as it does for vector addition. Figure 2.22 shows
how the dot product distributes over addition.
Now let's look at a special situation in which one of the vectors is the
unit vector pointing in the +x direction, which we'll denote as x . As shown
in Figure 2.23, the signed length of the projection is simply the x-coordinate
Search WWH ::




Custom Search