Game Development Reference
In-Depth Information
Here's the code that calculates the vector magnitude for our Vector class:
inline float Vector::Magnitude(void)
return (float) sqrt(x*x + y*y + z*z);
Note, you can calculate the components of a vector if you know its length and direction
angles . Direction angles are the angles between each coordinate axis and the vector, as
shown in Figure A-2 .
Figure A-2. Direction angles
The components of the vector shown in this figure are:
v x = | v | cos φ x
v y = | v | cos φ y
v z = | v | cos φ z
The cosines of the direction angles seen in these equations are known as direction co‐
sines . The sum of the squares of the direction cosines is always equal to 1:
cos 2 φ x + cos 2 φ y + cos 2 φ z = 1
The Normalize method normalizes, or converts, the vector to a unit vector satisfying
the following equation:
| v | = x 2 + y 2 + z 2 = 1
Search Nedrilad ::

Custom Search