• Advertisement
Sign in to follow this  

arbitrary rotation

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

hello, i have 2 polygons and i want the second one to have the same orientation as the first one. so i thought, i could calculate the angle between its normals and then apply a matrixtransformation to the second polygon. right? so, how can i get the corresponding rotation matrix out of the normals? i know i can get the angle using: but from that i dont know the axis? thanks!

Share this post


Link to post
Share on other sites
Advertisement
ok, that's not too difficult.

so you want to rotate from one direction to another. YOu can use the atan, acos, asin function to work out the angle between the two vectors, and then use that angle to rotate the object / vector so the orietnations match. It's a rather useful function, so you should keep it somewhere so you can reuse it for other purposes.


float CalculateAngle(Vector A, Vector B)
{
float dot = A.x * B.x + A.y * B.y;
float cross = A.x * B.y - A.y * B.x;
float angle = atan2(cross, dot);

return angle;
}




then you can rotate vertices using the angle.


Vector RotateVector(Vector A, Vector Centre, float angle)
{
float co = cos(angle);
float si = sin(angle);

Vector D = A - Centre;
Vector T;

T.x = D.x * co + D.y * si;
T.y = D.x *-si + D.y * co;
T += Centre;

return T;
}


Share this post


Link to post
Share on other sites
BTW, the rotation matrix would be


[ co si ]
[-si co ]



from the second routine.

Share this post


Link to post
Share on other sites
thank you!

so far i always used the dot product to calculate the angle,
but now with the cross product giving me the axis along which to rotate, it works!

Share this post


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

  • Advertisement