开发者

Question regarding Vector3.normalize();

After reading g开发者_开发知识库oogle, I still don't quite understand what this does/means? Could someone explain this? Possibly a simple example? Thank you very much.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜