[Math] How to rotate a 3d vector to be parallel to another 3d vector using quaternions

3dquaternionsrotationsvector-spaces

I have a vector $(a,b,c)$ and another vector $(d,e,f)$. I'm trying to rotate $(a,b,c)$ so its parallel to $(d,e,f)$ using quaternions. I need help understanding how I would do this.

I have so far that a quaternion is defined as

q = w + xi + yj + zk

so then I have

q1 = 0 + ai + bj + ck
q2 = 0 + di + ej + fk

But now I'm not sure what to do next…

Best Answer

I guess by "parallel" you intend "pointing in the same direction."

We may as well rotate $(d,e,f)$ in the plane spanned by $v=(d,e,f)$ and $w=(a,b,c)$. The axis of rotation would be around a vector perpendicular to this plane such as $a=v\times w$, which you'd normalize to a unit length vector $u$. Finally, we'd need the angle of rotation $\theta$, which can be retrieved from $v\cdot w =\|v\|\|w\|\cos(\theta)$ by solving for $\theta$.

Then following the scheme for using quaternions to perform rotations, the quaternion you're looking for is $q=\cos(\theta/2)+u\sin(\theta/2)$. The transformation $x\to qxq^{-1}$ moves $v$ to point in the same direction as $w$.