And vice-versa, given a quaternion, what is the angle and vector that represents that rotation?
I've read elsewhere that a vector can be converted to a quaternion by v_to_q : [x,y,z] -> (0, x, y, z).
So if on one hand I take a vector v_0, and rotate it about vector v by angle a to get vector v_1,
and on the other hand I take the quaternion v_to_q(v_0), and apply the same rotation in quaternion form (i.e. the quaternion represented by angle a and vector v),
then I should get the same quaternion as what v_1 maps to: v_to_q(v1). Right?
Quaternion product
The quaternion product is defined like so: \begin{equation} \begin{split} \mathbf{p} \otimes \mathbf{q} &= \left( p_0 + p_1 i + p_2 j + p_3 k\right) \left( q_0 + q_1 i + q_2 j + q_3 k\right) \\ &= p_0q_0 + p_0q_1 i + p_0q_2 j + p_0q_3 k \\ & + p_1 q_0 i - p_1 q_1 + p_1 q_2 k - p_1 q_3 j \\ & + p_2 q_0 j - p_2 q_1 k - p_2 q_2 + p_2 q_3 i \\ & + p_3 q_0 k + p_3 q_1 j - p_3 q_2 i - p_3 q_3 \\ &= ( p_0 q_0 - p_1 q_1 - p_2 q_2 - p_3 q_3) \\ &+ ({\color{blue} p_0q_1} + {\color{red}p_1 q_0} + p_2 q_3 - p_3 q_2)i \\ &+ ({\color{blue} p_0 q_2} - p_1 q_3 + {\color{red} p_2 q_0} + p_3 q_1)j \\ &+ ({\color{blue} p_0 q_3} + p_1 q_2 - p_2 q_1 + {\color{red}p_3 q_0})k \end{split} \end{equation} This can be simplified by writing $\mathbf{q} = (q_0, \vec{q})$, where $\vec{q}$ is the non-real part, $\vec{q} = q_1 \hat{i} + q_2 \hat{j} + q_3 \hat{k}$. This non-real part of the quaternion can be thought of as a vector, and its operations (dot and cross product) are defined similarly. Then, the result is \begin{equation} \mathbf{p} \otimes \mathbf{q} = (p_0 q_0 - \vec{p} \cdot \vec{q}, {\color{blue} p_0\vec{q}} + {\color{red} q_0\vec{p}} + \vec{p}\times \vec{q}) \end{equation} This is the so called Hamilton product. It is associative but not commutative.
If the quaternions are thought of as $4 \times 1$ matrices ($\mathbf{q} = \left[q_0, q_1, q_2, q_3 \right]^T$), the multiplication of two quaternions can be carried out by the following matrix product :
\begin{equation} \begin{split} \mathbf{p} \otimes \mathbf{q} &= \underbrace{ \left[ \begin{array}{cccc} % This is the correct matrix p_0 & -p_1 & -p_2 & -p_3 \\ p_1 & p_0 & -p_3 & p_2 \\ p_2 & p_3 & p_0 & -p_1 \\ p_3 & -p_2 & p_1 & p_0 \\ \end{array} \right]}_{=P} \left[ \begin{array}{c} q_0 \\ q_1 \\ q_2 \\ q_3 \\ \end{array} \right] \\ &= {\color{blue} p_0 } \left[ \begin{array}{c} q_0 \\ {\color{blue} q_1 } \\ {\color{blue} q_2 } \\ {\color{blue} q_3 } \\ \end{array} \right] + \left[ \begin{array}{c|ccc} 0 & -p_1 & -p_2 & -p_3 \\ \hline {\color{red} p_1} & 0 & -p_3 & p_2 \\ {\color{red} p_2} & p_3 & 0 & -p_1 \\ {\color{red} p_3} & -p_2 & p_1 & 0 \\ \end{array} \right] \left[ \begin{array}{c} q_0 \\ q_1 \\ q_2 \\ q_3 \\ \end{array} \right] \end{split} \end{equation}
Some additional definitions
Let us define the quaternion conjugate and norm (modulus) as follows: \begin{equation} \mathbf{q}^* = (q_0, -\vec{q}) \end{equation} \begin{equation} \left| \mathbf{q} \right| = \sqrt{q_0^2 + q_1^2 + q_2^2 + q_3^2} \end{equation} Now we see that \begin{equation} \mathbf{q} \otimes \mathbf{q}^* = (q_0^2 + \left| \mathbf{q} \right|^2, 0) \qquad \Rightarrow \qquad \frac{1}{q_0^2 + \left| \mathbf{q} \right|^2} \mathbf{q} \otimes \mathbf{q}^* = (1,0) = 1 \end{equation} Consequently, every nonzero element has a multiplicative inverse and the system of quaternions is a skew field. Furthermore, the norm of the (quaternion) product of two quaternions equals the product of their norms. This means that the product of two unit quaternions is also a unit quaternion.
The inverse of the rotation quaternion is the same as its conjugate: \begin{equation} \mathbf{r}^{-1} = \mathbf{r}^* \end{equation} The quaternion product of two unit conjugates is the conjugate of the product the other way around: \begin{equation}\ \begin{split} \mathbf{r}_1^{*} \otimes \mathbf{r}_2^{*} &= (r_{10}, \vec{r}_1) \times (r_{20}, \vec{r}_2) \\ &= (r_{10} r_{20} - \vec{r_1} \cdot \vec{r_2} , - r_{10}\vec{r}_2 - r_{20}\vec{r}_1 - \vec{r}_2 \times \vec{r}_1) \\ &= \left(\mathbf{r}_2 \otimes \mathbf{r}_1 \right)^{*} \\ \end{split} \end{equation}
Vector rotations with quaternions
Define a vector quaternion $(0,\vec{v}) = \mathbf{v}$ and a rotation quaternion $\mathbf{r} = (\cos{\tfrac{\theta}{2}}, \sin{\tfrac{\theta}{2}} \vec{r})$ for some unit vector $\vec{r}$. Now we can calculate the conjugation of $\mathbf{v}$ by $\mathbf{r}$ \begin{equation} \begin{split} \mathbf{r} \star \mathbf{v} &= \mathbf{r} \otimes \mathbf{v} \otimes \mathbf{r}^* = \mathbf{r} \otimes (0,\vec{v}) \otimes (\cos{\tfrac{\theta}{2}}, - \sin{\tfrac{\theta}{2}} \vec{r}) \\ &= \mathbf{r} \otimes (0 + \vec{v} \cdot \sin{\tfrac{\theta}{2}} \vec{r} , 0 + \cos{\tfrac{\theta}{2}} \vec{v} + \vec{v}\times (- \sin{\tfrac{\theta}{2}} \vec{r})) \\ &= \mathbf{r} \otimes (\sin{\tfrac{\theta}{2}}\vec{v} \cdot \vec{r} , \cos{\tfrac{\theta}{2}} \vec{v} + \sin{\tfrac{\theta}{2}}\vec{r}\times \vec{v}) \\ &= (\cos{\tfrac{\theta}{2}}, \sin{\tfrac{\theta}{2} \vec{r}}) \otimes (\sin{\tfrac{\theta}{2}}\vec{v} \cdot \vec{r} , \cos{\tfrac{\theta}{2}} \vec{v} + \sin{\tfrac{\theta}{2}}\vec{r}\times \vec{v}) \\ &= (\cos{\tfrac{\theta}{2}}\sin{\tfrac{\theta}{2}}\vec{v} \cdot \vec{r} - (\sin{\tfrac{\theta}{2} \vec{r}})\cdot(\cos{\tfrac{\theta}{2}} \vec{v} + \sin{\tfrac{\theta}{2}}\vec{r}\times \vec{v}), \\ & \cos{\tfrac{\theta}{2}}(\cos{\tfrac{\theta}{2}} \vec{v} + \sin{\tfrac{\theta}{2}}\vec{r}\times \vec{v}) + (\sin{\tfrac{\theta}{2}}\vec{v} \cdot \vec{r} )(\sin{\tfrac{\theta}{2} \vec{r}}) + (\sin{\tfrac{\theta}{2} \vec{r}}) \times (\cos{\tfrac{\theta}{2}} \vec{v} + \sin{\tfrac{\theta}{2}}\vec{r}\times \vec{v})) \\ &= (\cos{\tfrac{\theta}{2}}\sin{\tfrac{\theta}{2}}\vec{v} \cdot \vec{r} - \cos{\tfrac{\theta}{2}} \sin{\tfrac{\theta}{2} \vec{r}} \cdot \vec{v} - \sin^2{\tfrac{\theta}{2}} \vec{r} \cdot(\vec{r}\times \vec{v}), \\ & \cos^2{\tfrac{\theta}{2}} \vec{v} + \cos{\tfrac{\theta}{2}}\sin{\tfrac{\theta}{2}}\vec{r}\times \vec{v} + \sin^2{\tfrac{\theta}{2}}(\vec{v} \cdot \vec{r} )\vec{r} + \sin{\tfrac{\theta}{2} \cos{\tfrac{\theta}{2}} \vec{r}} \times \vec{v} + \sin^2{\tfrac{\theta}{2} \vec{r}} \times (\vec{r}\times \vec{v})) \\ &= (0, \\ & \cos^2{\tfrac{\theta}{2}} \vec{v} + \sin^2{\tfrac{\theta}{2}}(\vec{v} \cdot \vec{r} )\vec{r} + 2\sin{\tfrac{\theta}{2}} \cos{\tfrac{\theta}{2}} \vec{r} \times \vec{v} + \sin^2{\tfrac{\theta}{2}} \vec{r} \times (\vec{r}\times \vec{v})) \\ \end{split} \end{equation} Additionally, it is known that $\vec{r} \times ( \vec{r} \times \vec{v}) = (\vec{r} \cdot \vec{v})\vec{r} - (\vec{r} \cdot \vec{r}) \vec{v} = (\vec{r} \cdot \vec{v})\vec{r} - \vec{v} \Rightarrow \sin^2{\tfrac{\theta}{2}}(\vec{r} \cdot \vec{v})\vec{r} = \sin^2{\tfrac{\theta}{2}}\vec{r} \times ( \vec{r} \times \vec{v}) + \sin^2{\tfrac{\theta}{2}}\vec{v}$, resulting in \begin{equation} \mathbf{r} \star \mathbf{v} = \vec{v} + 2\sin{\tfrac{\theta}{2} \cos{\tfrac{\theta}{2}}} \vec{r} \times \vec{v} + 2\sin^2{\tfrac{\theta}{2}} \vec{r} \times (\vec{r}\times \vec{v}) \end{equation} or the so called Euler-Rodrigues formula for rotation. The resulting vector quaternion $\mathbf{v}^{'} = (0,\vec{v}^{'})$ represents the rotation of $\vec{v}$ around an arbitrary vector $\vec{r}$ by angle $\theta$ to produce the rotated vector $\vec{v}^{'}$.