Finding the smallest arc of rotation for a vector
Posted: Sun Feb 25, 2007 10:00 pm
Hello. For a while now, I've been trying to figure out (with reference to a couple threads on the GameDev forums) how to rotate vectors. I can't get it right. I'm doing:
Note that some of the code is probably unnecessary, due to the number of ways I've tried solving this problem, and the variables I've used for debugging, etc.
I found that the acos of product is always positive. I followed the advice of a thread on GD, and did the same but set the centre of rotation to the cross product of the two vectors, and got the same result. Also, I think that when product=0, acos(product) returns a non-number.
All I want to do is find out the shortest arc of rotation between one point and another point. Any help would be greatly appreciated.
Code: Select all
vector3df direction;
vector3df newDirection;
double product;
newDirection.X=mousePointAt.X-nodePos.X;
newDirection.Y=mousePointAt.Y-nodePos.Y;
newDirection.normalize();
direction.normalize();
product=(direction.dotProduct(newDirection));
direction.rotateXYBy(acos(product)*delta*100.0, direction.crossProduct(newDirection));
I found that the acos of product is always positive. I followed the advice of a thread on GD, and did the same but set the centre of rotation to the cross product of the two vectors, and got the same result. Also, I think that when product=0, acos(product) returns a non-number.
All I want to do is find out the shortest arc of rotation between one point and another point. Any help would be greatly appreciated.