# Quaternion Rotation Formula (Algebra)

I am currently in my last year of high school and I am looking at how quaternions are used for 3D animation for my math individual investigation and got to the section where a point p=[0,(x,y,z)] is rotated by angle θ about a unit axis n with a quaternion q=[w, v]=[cos(θ/2),n sin(θ/2)] and its inverse q^(-1)=[w, -v]=[cos(θ/2),-n sin(θ/2)] using:

p'=qpq^(-1)

The formula for the new point p' is then:

p'=p+2w(v x p)+2(v x (v x p))

I've been trying and using the standard definition of quaternion multiplication:

[w_1,v_1 ][w_1,v_2 ]=[w_1 w_2-v_1∙v_2,w_1 v_2+w_2 v_1+v_2×v_1 ]

But I can't seem to get to that new point formula.

How is it done algebraically?

• Welcome to MSE. Please use MathJax. – José Carlos Santos Dec 29 '17 at 0:12
• Where are you getting stuck? If you show your work, someone is more apt to show you where you might be going wrong. – amd Dec 29 '17 at 0:21
• Hint: somewhere along the way, you’ll need to use double-angle trig identities and the “BAC-CAB identity” for the cross product of three vectors. – amd Dec 29 '17 at 0:57
• One other thing that might be causing you trouble is that you’ve got a sign error in your target expression for $p'$. If you work out what it gives for $\vec n = (0,0,1)$ and $\vec p = (x,y,0)$, you’ll find that it represents a rotation through $-\theta$ instead of $\theta$. – amd Dec 30 '17 at 0:27
• You can find a derivation here. – amd Jan 4 '18 at 1:49

## 1 Answer


If you have a unit quaternion $\hat q$ then it consists of the scalar (or real) part $q_0$ and the vector (or imaginary) part $\vecq$: $$\hat q=\begin{bmatrix}q_0\\\vecq\end{bmatrix}$$

Suppose you have a point in space $\vecv=\textstyle\begin{bmatrix}x\\y\\z\end{bmatrix}$ then you can identify it with a quaternion $\hat v$: $$\hat v = \begin{bmatrix}0\\\vecv\end{bmatrix}.$$

If you want to apply the rotation that is encoded in the unit quaternion $\hat q$ to the vector $\vecv$ you do, as you wrote $$\hat v' = \hat q\circ \hat v\circ \hat q^{-1},$$ where $\circ$ denotes quaternion multiplication and then use the vector part of $\hat v'$ as the rotated vector $\vecv'$.

You already know $$\begin{bmatrix}q_0\\\vecq\end{bmatrix}\circ\begin{bmatrix}p_0\\\vecp\end{bmatrix} = \begin{bmatrix}p_0 q_0 -\vecq\cdot\vecp\\p_0 \vecq + q_0\vecp + \vecq\times\vecp\end{bmatrix},$$ where $\cdot$ is the dot product of two vectors and for a unit quaternion $$\hat q^{-1} = \begin{bmatrix}q_0\\\vecq\end{bmatrix}^{-1}=\begin{bmatrix}q_0\\-\vecq\end{bmatrix}.$$ Now we try to simplify the rotation. For this, we will first apply our quaternion multiplication two times, then expand the terms and use that $(\vecq\times\vecv)\cdot\vecq = 0$, since $\vecq\times\vecv$ is perpendicular to $\vecq$ by definition, $\vecq\times\vecv=-\vecv\times\vecq$, the BAC-CAB identity $\veca\times(\vecb\times\vecc) = \vecb(\veca\cdot\vecc) - \vecc(\veca\cdot\vecb)$ and that $\hat q$ is a unit quaternion $q_0^2 + \vecq\cdot\vecq = 1$. \begin{align} \hat v' &= \hat q \circ \hat v\circ \hat q^{-1} =\begin{bmatrix}q_0\\\vecq\end{bmatrix}\circ\begin{bmatrix}0\\\vecv\end{bmatrix}\circ \hat q^{-1}\\ &=\begin{bmatrix}0 - \vecq\cdot\vecv\\q_0\vecv + \boldsymbol{0} +\vecq\times\vecv\end{bmatrix}\circ\begin{bmatrix}q_0\\-\vecq\end{bmatrix}\\ &=\begin{bmatrix}-(\vecq\cdot\vecv)q_0 - (q_0\vecv + \vecq\times\vecv)\cdot(-\vecq)\\ q_0(q_0\vecv + \vecq\times\vecv) + (-\vecq\cdot\vecv)(-\vecq) + (q_0\vecv + \vecq\times\vecv)\times(-\vecq)\end{bmatrix}\\ &=\begin{bmatrix}-(\vecq\cdot\vecv)q_0 + q_0(\vecv\cdot\vecq) - (\vecq\times\vecv)\cdot\vecq\\ q_0^2\vecv + q_0\vecq\times\vecv + (\vecq\cdot\vecv)\vecq - q_0\vecv\times\vecq - (\vecq\times\vecv)\times\vecq\end{bmatrix}\\ &=\begin{bmatrix}0\\ q_0^2\vecv + 2q_0\vecq\times\vecv + (\vecq\cdot\vecv)\vecq + \vecq\times(\vecq\times\vecv)\end{bmatrix}\\ &=\begin{bmatrix}0\\ (q_0^2+\vecq\cdot\vecq)\vecv - (\vecq\cdot\vecq)\vecv+ 2q_0\vecq\times\vecv + (\vecq\cdot\vecv)\vecq + \vecq\times(\vecq\times\vecv)\end{bmatrix}\\ &=\begin{bmatrix}0\\ \vecv + 2q_0\vecq\times\vecv + \vecq(\vecq\cdot\vecv) - \vecv(\vecq\cdot\vecq) + \vecq\times(\vecq\times\vecv)\end{bmatrix}\\ &=\begin{bmatrix}0\\ \vecv + 2q_0\vecq\times\vecv + 2\vecq\times(\vecq\times\vecv)\end{bmatrix}. \end{align} From this, we get the formula for the rotated vector $\vecv'$: $$\vecv' = \vecv + 2q_0\vecq\times\vecv + 2\vecq\times(\vecq\times\vecv).$$

(Note that you have some errata in your question, like wrong signs etc.)