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.
source
share