Working out a vector’s magnitude
By drawing and working with vectors, it’s obvious to see they have a length. This is something that also distinguishes them from a point. The magnitude or length of a vector is useful for calculating the distance between where it starts and where it ends. For example, in Figure 9.3, we calculated the vector the pirate had to travel to get from a starting location to the treasure. From this vector, we can see the direction of travel, but we can also calculate how far the pirate is from the treasure. A very common operation to perform in graphics when it comes to moving objects is determining how far objects are apart, as well as working with collisions and a multitude of other functions. Therefore, it’s useful to understand how the magnitude is calculated.
To perform this operation, we must go back to Pythagoras theorem and triangles. Essentially, every vector can be made into a right-angled triangle. From there, the vector...