Hello. Since I’ve trying to do more complex things using scripting I would need to know more mathematical stuff. I’ve come up so developers saying ‘normalized’ CFrame/Vector3.
However I don’t know what normalized CFrame or Vector3 means, I don’t know if I missed any topic where this is being explained but I could not find one. If anyone knows what this means I would appreciate it you to explain it. Thanks
A normalized vector is a vector with a magnitude of 1, and is commonly associated with properties of CFrames (LookVector, UpVector, RightVector)
It’s also commonly referred to as a directional vector
You can get the normal of any Vector by getting its .Unit:
local Vector0 = Vector3.new(5,9,2) -- make some random Vector3 for example
local Vector0Magnitude = Vector0.Magnitude -- 10.488; not normalized
local NormalizedVector = Vector0.Unit -- this is what you're looking for
local NormalizedMagnitude = NormalizedVector.Magnitude -- always 1
print(NormalizedVector) -- Vector3 0.476, 0.858, 0.190
You can get the LookVector of a CFrame by defining its .LookVector
local CFrame0 = CFrame.new() -- can be any
local LookVector = CFrame0.LookVector
print(LookVector) -- Vector3 0, 0, -1
You’d want to ‘normalize’ a vector into what’s known as a ‘unit vector’ (a vector with length 1, hence the name ‘unit’) when you do for example angle calculations, so you’d only care about the vectors direction and not the actual magnitude information. It’s not a ‘must’ but it makes a lot of calculation easier.
When you normalize a vector with the .Unit property it returns that vector with the same direction but a magnitude of 1, a use case is normalizing the vector to get its direction alone
When you have a vector: Vector3.new(5,5,8) and get its Unit, this is what mathematically has happened:
First it calculates the magnitude of the current vector:
Vector3.X = 5 → 5^2 = 25 which is the same as doing 5 multiplied by 5 = 25
Vector3.Y = 5 → 5^2 = 25 which is the same as doing 5 multiplied by 5 = 25
Vector3.Z = 8 → 8^2 = 64 which is same as doing 8 multiplied by 8 = 64
After you have these 3 new values 25, 25, 64 you add them all up:
25 + 25 + 64 = 114 and then you calculate the square root of 114 which looks like: √ 114 → 10.6770783
Now when you have this magnitude value 10.6770783 we can calculate the Unit as follows:
Yep! Now all you can do is multiply by a certain amount to move along that direction. The ‘starting point’ is Vec3 0,0,0 and it will give the Unit length toward the Vector point target.
Basically the entire idea behind a “normalized” vector is exactly what the name implies
You “normalize” it in that you make some part of the vector “normal” or predictable, in this case the length
Many math problems require that you have a specific length value in a vector, such as:
dot product
trigonometry (as in the unit circle)
matrix math like cframes
And really countless other things
Having a known length of 1 also helps with, like he said, giving a vector a certain length
When you have a normalized vector and you multiply it by 2, or 3, or 4 or any number, the length becomes that number with the specific direction
But honestly, in the end, the use of normalized vectors isnt really limited to any of these things, its just another commonly used tool in math
Wherever a math problem could be solved by knowing a specific length, normalized vectors are useful, but you really just have to use your creativity