Getting a quaternion to rotate between two vectors

I have a couple of vectors. How can I create a quaternion that rotates from one to another?

+5
source share
1 answer

The unit quaternion q = cos (F) + u * sin (F) is the rotation of the vector v by an angle 2 * F about the u axis .

If your vectors are v and w , then we need to normalize them, then we calculate the angle between them as 2 * F = ArcCos (Dot ( v , w )). The direction vector of the rotation axis u = Normalize (VectorProduct ( v , w )). Now we can build the necessary quaternion of rotation.

+9
source

All Articles