- Home /
The question is answered, right answer was accepted
Vector normalization question
When normalized, a vector keeps the same direction but its length is 1.0.
Can someone explain to me what normalization does and how/why it's used? A vector is a point. But it has direction and a length ?
Answer by Eric5h5 · Mar 17, 2011 at 06:52 PM
A vector is either a point, or a direction. See the Ray struct, for example. It's two Vector3s, and the first Vector3 is the origin and the second Vector3 is the direction. If it's a direction, then it has a length. Vector3(0, 0, 5) is a direction of 5 units along the z axis, so it has a length of 5. If you normalize that, it's Vector3(0, 0, 1). You would do this when you only want the direction and don't care about the length.
After normaliIng and getting V3(0,0,1) which tells us that it is in the z axis direction. That let's us know which axis it's direction but what if the direction isn't on an axis and perhaps at a 45 degree angle. Rather than having it be on the axis. How would you show diagonal? V3(0,1,1)?
Yes, (0, 1, 1) is 45 diagonal, though the length is greater than 1. If you normalized it, it would be approximately (0, .707, .707).
Answer by biebuster · Oct 04, 2015 at 12:41 PM
Alright let's say that we want to find the normalized version of (2, 4, 0)
First just to clear up any confussion: the magnitude (or length!) is:
//The square root of: x * x + y * y + z * z
Now when we normalize something, that magnitude needs to be 1. Alright now for the actual explanation.
So first of all let's find out how we find the direction. imagine we have a vector called: 0, 4, 0. you have this cordinate system here: http://i.imgur.com/pUp8SX3.png So bassicly we're taking our vector and comparing it to the absoloute 0, 0, 0, place of our coordinate. And in our case, compared to our vector of 0, 4, 0 the direction only goes upwards. That's why the direction then ends up being 0, 1, 0
0, 4, 0 direction = 0, 1, 0;
Now if it was 0, 2, 0, this would happen: http://imgur.com/GPhlI4w
Aright let's take a vector that has these values: 4, 4, 0; if we had a vector with 4, 4, 0 then this would happen: http://i.imgur.com/BX1CCNR.png
In this case you'd be able to have any values at x, and y, AND if those values were excatly the same it would give: 1, 1, 0
4, 4, 0 direction = 1, 1, 0
finally let's take our 2, 4, 0 vector. http://i.imgur.com/xNM4JNG.png
2, 4, 0 direction = 1, 2, 0;
But what does this have to do with normalization? well let's take the 3 direction vectors we had before:
4, 4, 0 direction = 1, 1, 0;
0, 4, 0 direction = 0, 1, 0;
2, 4, 0 direction = 1, 2, 0;
When we want the normalization we want the magnitude of these values. So let's find the magnitude here:
//1, 1, 0 magnitude = square root of: 1 * 1 + 1 * 1 = 1.41;
//0, 1, 0 magnitude = square root of: 1 * 1 = 1;
//1, 2, 0 magnitude = square root of: 1 * 1 + 2 * 2 = 2.23;
0, 1, 0 doesn't need to be normalized cause it's magnitude is 1! perfect!
1, 1, 0 however needs to be normalized. And sadly the only way to do this is just let a computer divide it by what makes it go down to 1. Not something we would easily be able to calculate. Same goes for 1, 2, 0
And that is that! I know this comment is from 2011, but this answer was mostly made to help people like me who really strucled with it, even after reading these other answers, and the unity documentation. or it's just 1 hour of my life wasted have a good day
Answer by flaviusxvii · Mar 17, 2011 at 06:29 PM
A vector exists in a vector space, which has an origin. So every "point" is a line from the origin to that point.
The vector [1, 1, 1] is a line from [0, 0, 0] to [1, 1, 1].
Normalizing a vector preserves the direction, but moves the point to exactly one unit from the origin.
Top Lad. $$anonymous$$uch appreciated for explaining it in plain english. Now i get it we're only moving the object 1 vector unit across between two points or 1 unit of magnitude across...
Answer by Owen-Reynolds · Mar 18, 2011 at 04:22 PM
A use for normalize:
// bullet is speed 5, aimed at timmy:
float3 v = ((timmy.transform.position - transform.position).Normalized)*5;
bullet.velocity = v;
The Normalized converts the gap between timmy and myself to length 1, and the *5 gives the bullet a speed of 5.
bullet.LookAt("timmy"); bullet.rigidbody.velocity = bullet.forward*5;
is the more common way (in Unity) of doing it. Normalized is often used for the oddball "I have the right direction, but it's the wrong length" problems, or when you can't use LookAt.
Answer by sparkzbarca · Mar 04, 2013 at 03:36 AM
a normalized vector is the slope of the line on which the vector lies (of course this is only useful if the vector represents a line more commonly referred to as a direction)
knowing the slope of a line is useful a lot so it's a common operation.
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
What is the difference between Normalize & Normalized 1 Answer
Vector2 Normalize ? 3 Answers
Vector3.Normalize not working for particular input? 2 Answers