Advertisement

make vectors normalized

Started by October 29, 2002 07:27 PM
4 comments, last by robsonde 22 years, 4 months ago
how do I make vectors normalized? can some one show some simple code/math? thanks lots
If for example you have a 3-d vector (x,y,z) = V

then the length of the vector, |V| = sqrt(x^2+y^2+z^2)

and the normalized vector V is V/|V|
or
(x / sqrt(x^2+y^2+z^2), y/sqrt(x^2+y^2+z^2), z/sqrt(x^2+y^2+z^2))

this makes the length of the normalized vector 1

edit: screwed up formatting

[edited by - Cold_Steel on October 29, 2002 8:35:00 PM]
______________________________"Man is born free, and everywhere he is in chains" - J.J. Rousseau
Advertisement
so a normalized vector has same "direction" but always has a length of 1.

is that right?

Exactly.
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
oh yeah, know first if you really want your vector normalized, that sqrt() might slow down your code somewhat.... Some situations you don''t need to normalize your vector you see....

-----------------------------
http://nomad.openglforums.com
-----------------------------
Usually, you don''t find the normals (and normalize them) in real time, but only once. So, the SQRT is not a problem.

This topic is closed to new replies.

Advertisement