$$\def\complex#1#2{\left(#1,#2\right)} \def\real#1{\complex{#1}{\vec{0}}} \def\img#1{\complex{0}{#1}} \def\tuple#1#2{\left(#1,#2\right)} \def\Cos#1{\cos\left(#1\right)} \def\Sin#1{\sin\left(#1\right)} \def\group#1{\left(#1\right)}$$
Rotate points using quaternions
$$% Arcus cosine. \def\acos{\cos^{-1}} % Vector projection. \def\projection#1#2{{proj_{#1}\left(#2\right)}} % Vector rejection. \def\rejection#1#2{{rej_{#1}\left(#2\right)}} % Norm. \def\norm#1{{\left\|#1\right\|}} % Cross product. \def\cross#1#2{\mathit{cross}\left(#1,#2\right)} % Dot product. \def\dot#1#2{{#1 \cdot #2}} % Magnitude. \def\mag#1{{\left|#1\right}} \def\group#1{\left(#1\right)}} \def\sbgrp#1{\left\{#1\right\}}$$

## The sandwich product for unit quaternions

Let $$\mathbf{p}=(0,\vec{p})$$ a point quaternion and $$\mathbf{q}=(w,\vec{v})$$ a unit quaternion. We show that the result of $\mathbf{q} \mathbf{p} \mathbf{q}^{-1}$ is a point vector $\vec{p}' = 2\group{\vec{v}\vec{p}} \vec{v} + \vec{p}(2w^2 - 1) + \cross{\vec{v}}{\vec{p}}2w$

### Proof

\begin{aligned} &\mathbf{q} \mathbf{p} \mathbf{q}^-1 \end{aligned}
See "Quaternion corresponding to a vector". Quaternion multiplication is associative.
\begin{aligned} &=\group{w,\vec{v}} \group{0,\vec{p}} \group{w,-\vec{v}}\\ &=\group{\group{w,\vec{v}} \group{0,\vec{p}}} \group{w,-\vec{v}} \end{aligned}
The definition of the Quaternion product \begin{aligned} \group{w_1 w_2 - v_1 v_2, w_1 v_2 + w_2 v_1 + \cross{v_1}{v_2}} \end{aligned} with $$w_2 = 0$$ reduces to \begin{aligned} \group{-v_1 v_2, w_1 v_2 + \cross{v_1}{v_2}} \end{aligned} With $$w_1 = w$$, $$v_1 = \vec{v}$$, and $$v_2 = \vec{p}$$ we obtain
\begin{aligned} &=\group{-\vec{v}\vec{p}, w\vec{p} + \cross{\vec{v}}{\vec{p}}} \group{w, -\vec{v}} \end{aligned}
The definition of the Quaternion product \begin{aligned} \group{w_1 w_2 - v_1 v_2, w_1 v_2 + w_2 v_1 + \cross{v_1}{v_2}} \end{aligned} With $$w_1 = -\vec{v}\vec{p}$$, $$w_2 = w$$, $$v_1 = w\vec{p} + \cross{\vec{v}}{\vec{p}}$$, and $$v_2 = -\vec{v}$$ we obtain
\begin{aligned} &=\group{-\vec{v}\vec{p} w - \group{w\vec{p} + \cross{\vec{v}}{\vec{p}}} \group{-\vec{v}}, \group{-\vec{v}\vec{p}} \group{-\vec{v}} + w \group{w\vec{p} + \cross{\vec{v}}{\vec{p}}} + \cross{\group{-\vec{v}}}{\left(w\vec{p} + \cross{\vec{v}}{\vec{p}\right)}}}\\ \end{aligned}
By \begin{aligned} &-\vec{v}\vec{p} w - \group{w\vec{p} + \cross{\vec{v}}{\vec{p}}} \group{-\vec{v}}\\ =&-\vec{v}\vec{p} w - w\vec{p}\group{-\vec{v}} - \cross{\vec{v}}{\vec{p}}\group{-\vec{v}}\\ =&-\vec{v}\vec{p} w + \vec{p}\group{\vec{v}} w + \cross{\vec{v}}{\vec{p}}\group{\vec{v}}\\ =&\cross{\vec{v}}{\vec{p}}\group{\vec{v}}\\ \end{aligned} As $$\vec{v}$$ is orthogonal to $$\cross{\vec{v}}{\vec{p}}$$, it follows that $$\cross{\vec{v}}{\vec{p}}\group{\vec{v}} = 0$$. Hence we obtain
\begin{aligned} &=\group{0, \group{-\vec{v}\vec{p}} \group{-\vec{v}} + w \group{w\vec{p} + \cross{\vec{v}}{\vec{p}}} + \cross{\group{-\vec{v}}}{\left(w\vec{p} + \cross{\vec{v}}{\vec{p}\right)}}}\\ \end{aligned}
The imaginary part is $$0$$ hence this simplifies to
\begin{aligned} &= \group{-\vec{v}\vec{p}} \group{-\vec{v}} + w \group{w\vec{p} + \cross{\vec{v}}{\vec{p}}} + \cross{-\vec{v}}{w\vec{p} + \cross{\vec{v}}{\vec{p}}} \end{aligned}
$$\group{-\vec{v}\vec{p}} \group{-\vec{v}} = \group{\vec{v}\vec{p}} \group{\vec{v}}$$
$$w \group{w\vec{p} + \cross{\vec{v}}{\vec{p}}} = \vec{p}w^2 + \cross{\vec{v}}{\vec{p}}w$$
\begin{aligned} &= \group{\vec{v}\vec{p}} \vec{v} + \vec{p}w^2 + \cross{\vec{v}}{\vec{p}}w + \cross{-\vec{v}}{w\vec{p} + \cross{\vec{v}}{\vec{p}}} \end{aligned}
$$\cross{a}{b+c} = \cross{a}{b}+\cross{a}{c}$$ (Cross product is distributive over addition)
\begin{aligned} &= \group{\vec{v}\vec{p}} \vec{v} + \vec{p}w^2 + \cross{\vec{v}}{\vec{p}}w + \cross{-\vec{v}}{w\vec{p}} + \cross{-\vec{v}}{\cross{\vec{v}}{\vec{p}}} \end{aligned}
$$\cross{sa}{b} = \cross{a}{sb} = s\cross{a}{b}$$ (Cross product is compatible with scalar multiplication)
\begin{aligned} &= \group{\vec{v}\vec{p}} \vec{v} + \vec{p}w^2 + \cross{\vec{p}}{\vec{v}}w - \cross{\vec{v}}{\vec{p}}w - \cross{\vec{v}}{\cross{\vec{p}}{\vec{v}}} \end{aligned}
$$\cross{a}{\cross{b}{c}} = b(ac) - c(ab)$$ (Triple product)
with $$a = c = \vec{v}$$ and $$b = \vec{p}$$ gives $$\vec{p}(\vec{v}\vec{v}) - \vec{v}(\vec{v}\vec{p}) = \vec{p}(\vec{v}\vec{v}) - (\vec{v}\vec{p})\vec{v}$$ We obtain
\begin{aligned} &= \group{\vec{v}\vec{p}} \vec{v} + \vec{p}w^2 + \cross{\vec{p}}{\vec{v}}2w - \vec{p}(\vec{v}\vec{v}) + (\vec{v}\vec{p})\vec{v} \end{aligned}
$$\mathbf{q}$$ is a unit quaternion, $$\vec{v}\vec{v} = 1 - w^2$$ holds. We obtain
\begin{aligned} &= 2\group{\vec{v}\vec{p}} \vec{v} + \vec{p}w^2 + \cross{\vec{v}}{\vec{p}}2w - \vec{p}(1 - w^2)\\ &= 2\group{\vec{v}\vec{p}} \vec{v} + \cross{\vec{v}}{\vec{p}}2w + \vec{p}w^2 - \vec{p} + \vec{p}w^2\\ &= 2\group{\vec{v}\vec{p}} \vec{v} + \cross{\vec{v}}{\vec{p}}2w + \vec{p}(2w^2 - 1) \end{aligned}

## The sandwich product for rotation quaternions

Let $$\mathbf{p}=(0,\vec{p})$$ a point quaternion and $$\mathbf{q}=(\cos\left(\frac{\alpha}{2}\right),\hat{r}\sin\left(\frac{\alpha}{2}\right))$$ a rotation quaternion. We show that the result of $\mathbf{q} \mathbf{p} \mathbf{q}^{-1}$ is a point vector $\vec{p}' = 2\group{\vec{v}\vec{p}} \vec{v} + \cross{\vec{v}}{\vec{p}}2w + \vec{p}(2w^2 - 1)$

### Proof

\begin{aligned} &\mathbf{q} \mathbf{p} \mathbf{q}^-1 \end{aligned}
By "The sandwich product for unit quaternions" and with $$w = \cos\left(\frac{\alpha}{2}\right)$$ and $$\vec{v} = \hat{r}\sin\left(\frac{\alpha}{2}\right)$$ we obtain.
\begin{aligned} 2\group{\hat{r}\sin\left(\frac{\alpha}{2}\right)\vec{p}}\hat{r}\sin\left(\frac{\alpha}{2}\right) + \cross{\hat{r}\sin\left(\frac{\alpha}{2}\right)}{\vec{p}}2\cos\left(\frac{\alpha}{2}\right) + \vec{p}\group{2\cos^2\left(\frac{\alpha}{2}\right) - 1} \end{aligned}
\begin{aligned} \group{\hat{r}\vec{p}}\hat{r}2\sin^2\left(\frac{\alpha}{2}\right) + \cross{\hat{r}}{\vec{p}}2\cos\left(\frac{\alpha}{2}\right)\sin\left(\frac{\alpha}{2}\right) + \vec{p}\group{2\cos^2\left(\frac{\alpha}{2}\right) - 1} \end{aligned}
$$\cos\left(2\omega\right) = 2\cos^2\left(\omega\right) - 1$$
$$\sin\left(2\omega\right) = 2\cos\left(\omega\right)\sin\left(\omega\right)$$
$$\sin^2\left(\frac{\omega}{2}\right) = \frac{1-\cos\left(\omega\right)}{2}$$
\begin{aligned} \group{\hat{r}\vec{p}}\hat{r}\left(1-\cos\left(\alpha\right)\right) + \cross{\hat{r}}{\vec{p}}\sin\left(\alpha\right) + \vec{p}\cos\left(\alpha\right) \end{aligned}
$$\projection{\vec{p}}{\hat{r}} = \left(\dot{\vec{p}}{\hat{r}}\right)\hat{r} = \left(\dot{\hat{r}}{\vec{p}}\right)\hat{r}$$
\begin{aligned} \projection{\vec{p}}{\hat{r}}\left(1-\cos\left(\alpha\right)\right) + \cross{\hat{r}}{\vec{p}}\sin\left(\alpha\right) + \vec{p}\cos\left(\alpha\right) \end{aligned}
\begin{aligned} \projection{\vec{p}}{\hat{r}} - \projection{\vec{p}}{\hat{r}}\cos\left(\alpha\right) + \cross{\hat{r}}{\vec{p}}\sin\left(\alpha\right) + \vec{p}\cos\left(\alpha\right) \end{aligned}
\begin{aligned} \projection{\vec{p}}{\hat{r}} + \cross{\hat{r}}{\vec{p}}\sin\left(\alpha\right) + \left(\vec{p} -\projection{\vec{p}}{\hat{r}}\right)\cos\left(\alpha\right) \end{aligned}
$$\rejection{\vec{p}}{\hat{r}} = \vec{p} - \projection{\vec{p}}{\hat{r}}$$
\begin{aligned} \projection{\vec{p}}{\hat{r}} + \cross{\hat{r}}{\vec{p}}\sin\left(\alpha\right) + \rejection{\vec{p}}{\hat{r}}\cos\left(\alpha\right) \end{aligned}
\begin{aligned} \rejection{\vec{p}}{\hat{r}}\cos\left(\alpha\right) + \cross{\hat{r}}{\vec{p}}\sin\left(\alpha\right) + \projection{\vec{p}}{\hat{r}} \end{aligned}

Observe this is the same formula as in Rotate points using axis-angles.