RoR
RoR

Reputation: 16472

Question regarding Vector3.normalize();

After reading google, I still don't quite understand what this does/means? Could someone explain this? Possibly a simple example? Thank you very much.

Upvotes: 1

Views: 2316

Answers (2)

jv42
jv42

Reputation: 8583

Normalizing a vector means changing its components so its total length is equal to 1.

In pseudo-code:

length = sqrt((vec.x * vec.x) + (vec.y * vec.y) + (vec.z * vec.z))
vec.x /= length
vec.y /= length
vec.z /= length

This has many uses in real-time 3D, as normed vectors have interesting properties.

Upvotes: 6

Jackson Pope
Jackson Pope

Reputation: 14640

Normalizing a vector scales it to length 1.0, without changing its direction.

Edit: This works by finding the length of the vector and then dividing each of the co-ordinates by the length:

length = sqrt(x*x + y*y + z*z);

norm = [ x / length, y / length, z / length];

Clearly you cannot normalize a zero-length vector.

Upvotes: 1

Related Questions