Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

jwblair

Normalizing Vectors...

This topic is 6295 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
V1 is a vector, ie. V1 = [5,2,3]
length/magnitude of V1, len = Sqrt((5*5)+(2*2)+(3*3))
normalized vector, V2 = [5/len , 2/len , 3/len]

Share this post


Link to post
Share on other sites
here is a simple c function:

void normalize(VECTOR * v)
{
float c = sqrt(v.x * v.x +v.y * v.y +v.z * v.z);
v.x/=c;
v.y/=c;
v.z/=c;

}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Here''s a small optimization you could use:

void normalize(VECTOR * v)
{
float c = 1.0f / sqrt(v.x * v.x +v.y * v.y +v.z * v.z);
v.x *= c;
v.y *= c;
v.z *= c;
}

A multiplication is around 12 times faster than a division, so you''ve only to divide one time.

It''s really a VERY SMALL amount of time you''ll save, but why not cause it''s only a minimal change.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!