
3.8 Normalizing Vectors
27
3.7°2
C++ API
The distance between two points is calculated using the MPoint's
di stanceTo
function.
MPoint pO( 1.0, 0.0, 0.0 )"
MPoint pl( 2.0, 0.0, 0.0 )"
double distance = pO.distanceTo( pl ).
3.8
NORMALIZING VECTORS
A vector that has a length of 1 is called a unit vector. To turn any vector into a unit
vector, it needs to be normalized. This is done as follows.
u
Ilull
Each component of the vector is divided by the vector's current length. The vector's
length will then be 1. Unit vectors are represented with the "hat" character (^) above
them. For a 3D vector the calculation ...