# How to rotate a 3d vector to be parallel to another 3d vector using quaternions?

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

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$.
• I don't understand what $u$ is. I can get \theta, but then how does qxq^-1 move v? Apr 1, 2014 at 19:59
• u is the quaternion representing the unit normal to the plane of rotation. It's a quaternion with real part zero just like v and w. X represents any quaternion with real part are (which represents a three dimensional real vector) v moves from v to $qvq^{-1}$ Apr 1, 2014 at 21:32
• I think that is just a typo: $a = v × w$ should read $u = v × w$
• @kd88 Actually the only typo was that I used both $u$ and $n$ when I meant the same thing. The point is that $a$ was not necessarily a unit vector. Nov 27, 2015 at 2:07