Skip to main content
gamedev.net
🔒 Locked

normalising a 3d vector

Started by Pendu Nov 2, 2005 at 7:34 AM 3 replies 650+ views
Original Post
Pendu
Pendu
Hello everyone, I wish to know what purpose normalising a vector has? Why would you want the length of a vector to equal to 1?
ReaVeR-Andrey
ReaVeR-Andrey
many many purposes.


  • lighting- you need a normal vector for every poly/vertex
  • direction- say you know where two objects are and you want a vector pointing from one object to another that has predefined length
  • many many more
SiCrane
SiCrane
It just makes the math easier in a lot of equations since if you don't have a normal vector going in you'll need to divide by the length in order to get a correct answer anyways. For example calculating angles via the dot product and arcsin.
haegarr
haegarr
An example: for lighting a surface point one computes the so-called "dot product" between the surface normal (what in fact is a direction vector) and the direction vector between the surface and the light source. The dot product is defined as follows:
a dot b = |a| * |b| * cos
what means that the result is linear with the length of vector a (== |a|), and the length of vector b (== |b|), and the cosine of the angle between vector a and vector b. However, for lighting one is interested _only_ in the dependence on the cosine, so one want the lengthes of both vectors to be 1 (see formula above).

Similar to this, there are many other situations where unit length is of advantage.

[Edited by - haegarr on November 2, 2005 10:53:11 AM]
Zakwayda
Zakwayda
Just to add to the above, here's some more info about when you may or may not need a unit-length vector:

Generally need unit length

Finding the exact distance from a point to a plane or line
Building an axis-angle rotation matrix
Building an axis-angle quaternion
Finding the angle between two vectors directly with acos()
Certain lighting calculations
Certain algorithms for 'rotate vector to vector' quaternion
Plane side tests for certain objects

Generally don't need unit length

Finding relative distance from a point to a plane (such as for polygon clipping)
A vector used as an axis in the separating axis test
Finding the angle between two vectors using dot/perp-dot/cross and atan2()
Finding out whether a polygon is facing the viewer
Certain other algorithms for 'rotate vector to vector' quaternion
Plane side tests for certain other objects

I may have overlooked something or gotten something in the wrong category, but the basic idea is to know when you do or don't need a unit-length vector, and normalize as appropriate. Since normalization is relatively expensive compared to other common operations, it's good to avoid it when you can.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.