Finding quaternion representing the rotation from one vector to another

Quaternion q;
vector a = crossproduct(v1, v2);
q.xyz = a;
q.w = sqrt((v1.Length ^ 2) * (v2.Length ^ 2)) + dotproduct(v1, v2);

Don’t forget to normalize q.

Richard is right about there not being a unique rotation, but the above should give the “shortest arc,” which is probably what you need.

Leave a Comment