The magnitude or length of a vector is written as the letter of the vector surrounded by two bars, . The magnitude of a vector is the square root of the dot product of the vector with itself:
In addition to implementing the magnitude function, we're also going to implement a magnitude squared function. The formula is the same, but it avoids the expensive square root operation:
In games we often compare the magnitude of a vector to known numbers; ...