# Dot Product

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

## 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 on other sites
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 on other sites
Cheers :) And no I'm not using DX, I'm using OpenGL so now I'm kinda lost :)

##### 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

1. 1
2. 2
3. 3
4. 4
Rutin
15
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633724
• Total Posts
3013556
×