Archived

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

Unit Vectors

This topic is 5750 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

I''ve just started learning 3D programming. I''m reading Advanced 3D Programming with D3D 8 by Peter Walsh. I''m somewhat confused though on unit vectors. He tells me to get the "unit length version" of a vector use n = M/|M|. What does "unit length version" mean? Is it the same as normalize? Why would you want to do this? Does it change to X,Y,Z values of the vector? He''s not to clear on this point in the book.

Share this post


Link to post
Share on other sites
A unit vector is a vector whose length is 1 unit (hence the name). A unit vector is the natural means of representing direction, and is then scaled by a scalar (now you know why they call them scalars) to yield a vector magnitude (such as applied force).

The simplest visualization I can think of it to construct a vector, V, with components of 1 in each of the axial directions X, Y and Z. What''s the magnitude of that vector? (Vx2 + Vy2 + Vz2)0.5. Is that value 1? No. How do we make it one? Divide it by itself, of course! So how do we make the magnitude of the original vector (V) 1? Divide each of its components by its magnitude.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!

Share this post


Link to post
Share on other sites
You do not usually do this to your vertices, but rather to your surface normals. The normals need to be length 1, becasue having this assumption speeds up the calculation of the illumination equation by removing a bunch of divisions. (The dot product of 2 unit vectors is cos of the angle between them. The magnitude of the cross product of 2 unit vectors is the sin of the angle between them). Making everything unit length to begin with avoids having to renormalize later.

Share this post


Link to post
Share on other sites
And (1,1,1) is not a unit vector. Its magnitude is ~1.73.

As invective said, vector, not vertex. We use vertices to define geometry, but we use vectors to define, well, vector quantities like velocity and acceleration. In a physical simulation, you would like for the collision of two objects to cause some form of reaction, right? Well that''s a vector operation (both the collision detection - ray-plane/plane-plane intersection tests - and the resultant collision response).

If a pong ball hits the paddle, it''s resultant direction is the result of a vector sum of its velocity and the paddle''s velocity (in the given world volume). That''s why if you back up just as a soccer ball is about to hit your leg, it bounces of more softly than if you moved forward. If you move forward quickly, it bounces off even harder.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!

Share this post


Link to post
Share on other sites
quote:
Original post by bitstream
So why would you want to make a vector of say (10, 5, 100) into (1, 1, 1)? Wouldn''t this make all of your 3d objects spheres?


(10,5,100) doesn''t turn into (1,1,1). You divide the whole vector by the magnitude, so:
mag(10,5,100)=100.6
thus your normalized vector is approximately (.099,.049,.99)

Share this post


Link to post
Share on other sites