Game Development Reference
In-Depth Information
If the vectors are unit vectors it can be simplified to:
Which will return the angle Ɵ in radians. One important thing to understand is that getting
the angle through the dot product will always give us the most interior angle, that is, the
angle will be in the range 0..π/2. If we don't pay attention to this we would undoubtedly
see some unexpected results when using the angle between vectors.
Figure 5 - The angle from the dot product yields an angle in the range 0..
If what we are really looking for is the exterior angle (Ɵ') then we can use a cross product
to determine the direction of the angle. The operation thus becomes:
In this case we are still using the angle we computed but we extend the range to be
-π..0..π depending on the use case rather than multiplying by the sign we may want to add
π when the sign is negative in order to get the exterior angle which would be in the range
0..2π.
The next important use of the dot product is as the projection of a vector u onto a vector v .
Search WWH ::




Custom Search