lesson

Updated 1 month ago Β· 5 views
When game developers program a laser beam, they need it to travel at exactly the same speed no matter where you aim. How do you keep a vector's exact direction while forcing its length to be exactly 1?
The answer is normalization β the process of scaling any non-zero vector down to a length of 1 without changing its path.
So what does a vector of length 1 look like mathematically?
What Is a Unit Vector?
A unit vector is any vector whose length, or magnitude, is exactly 1. We write a unit vector in the direction of v with a small caret called a "hat": u^ or v^.
πInteractive diagram
To find u^, we multiply the original vector v by the scalar reciprocal of its magnitude: u^=β₯vβ₯1βv=β₯vβ₯vβ
Why does this guarantee a length of 1? Because pulling the positive scalar β₯vβ₯1β outside the magnitude gives β₯u^β₯=ββ₯vβ₯1βββ₯vβ₯=β₯vβ₯β₯vβ₯β=1.
Let's put this formula to work on a concrete two-dimensional vector.
Normalizing in Two Dimensions
Suppose you have the vector v=β¨3,β4β©. First, compute its magnitude using the distance formula: β₯vβ₯=32+(β4)2β=9+16β=5.
Next, divide every component of v by 5: u^=5β¨3,β4β©β=β¨53β,β54ββ©
πInteractive diagram