To calculate a vector’s length, square the vector’s components, add the squares, and take the square root of the sum, which you can see in the following equation:
v = < x, y, z > ||v|| = sqrt[(x * x) + (y * y) + (z * z)]
You may also see a vector’s length referred to as the norm or the magnitude. The following example calculates the length of a 3D vector:
v = < 9, 2, 6 > ||v|| = sqrt[(9 * 9) + (2 * 2) + (6 * 6)] ||v|| = sqrt(81 + 4 + 36) = 11
A unit vector is a vector with a length of 1. Normalizing a vector converts a vector to a unit vector. To normalize a vector, divide each component by its length. Let’s normalize the vector from the previous example.
u = < 9 / 11, 2 / 11, 6 / 11 > u = < .818, .182, .545 >