Game Development Reference
In-Depth Information
}
};
To implement this product I have overloaded the % operator, simply because it
looks most like a cross. This operator is usually reserved for modulo division in most
languages, so purists may balk at reusing it for an unrelated mathematical operation.
If you are easily offended, you can use the longhand vectorProduct method instead.
Personally I find the convenience of being able to use operators outweighs any confu-
sion, especially as vectors have no sensible modulo division operation.
The Trigonometry of the Vector Product
Just like the scalar product, the vector product has a trigonometric correspondence.
This time the magnitude of the product is related to the magnitude of its arguments
and the angle between them, as follows:
|
a
×
b
|=|
a
||
b
|
sin θ
[2.6]
where θ is the angle between the vectors, as before.
This is the same as the scalar product, replacing the cosine with the sine. In fact
we can write
1
|
a
×
b
|=|
a
||
b
|
( a
·
b ) 2
using the relationship between cosine and sine:
cos 2 θ
sin 2 θ
+
=
1
We could use equation 2.6 to calculate the angle between two vectors, just as we
did using equation 2.4 for the scalar product. This would be wasteful, however: it is
much easier to calculate the scalar product than the vector product. So if we need to
find the angle (which we rarely do), then using the scalar product would be a faster
solution.
Commutativity of the Vector Product
You may have noticed in the derivation of the vector product that it is not commu-
tative. In other words, a
×
b
=
b
×
a . This is different from each of the previous
products of two vectors: both a
a .
In fact, by comparing the components in equation 2.5, we can see that
b
=
b
a and a
·
b
=
b
·
a
×
b
=−
b
×
a
This equivalence will make more sense once we look at the geometrical interpretation
of the vector product.
Search Nedrilad ::




Custom Search