Jump to content
  • Advertisement
Sign in to follow this  
DrunkenBrit

Dot Product

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

Hey, Example: I've found the angle between one object and another; object 1 needs to rotate to face object two. Is there any standard (or any) way to find if the vector (object) one needs to rotate CW or CCW to face object two? Cheers.

Share this post


Link to post
Share on other sites
Advertisement
One way is to take the cross product of the two vectors. That'll give you a vector perpendicular to both of the other two vectors. Then you can rotate around that vector by the angle between the other two angles. If you're using D3D, then the D3DXMatrixRotationAxis() function will do that for you.

Share this post


Link to post
Share on other sites
It not depends on your graphic api (with the exception of the handeness and matrix representation).

If u is the facing vector of object 1, p1 position of object 1, p2 position of object 2 and alpha the angle between object 1 and object 2 in radians.

u = normalized(p2 - p1)
rotAxis = u x v (u cross product with v)
then rotate u by alpha about rotAxis

if alpha is 0 or pi (or near that values; floating point precision) the above is not valid as rotAxis = 0, but then you only need to turn the facing u vector 180º when alpha near pi

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!