[Math] Finding the quaternion that performs a rotation

quaternions

I managed to find this answer here where Christian Rau says "axis/angle rotation (a,x,y,z) is equal to quaternion (cos(a/2),xsin(a/2),ysin(a/2),z*sin(a/2))"

Assuming I know what rotation I need to perform, how would I represent it?
eg, finding the quaternion that rotates 30 degrees around the z axis.

Any help would be greatly appreciated.

edit** I got as far as writing out "(cos(15),0,0," and then got confused on z * sin.

Best Answer

To rotate about the $z$ axis (yaw) by $\alpha$ you need the following quaternion

$\begin{aligned}q = \begin{bmatrix}\cos(\tfrac{\alpha}{2})\\0\\0\\\sin(\tfrac{\alpha}{2})\end{bmatrix}\end{aligned}\tag{1},$

to rotate about the $x$ (pitch) axis you need

$\begin{aligned}q = \begin{bmatrix}\cos(\tfrac{\alpha}{2})\\0\\ \sin(\tfrac{\alpha}{2})\\0\end{bmatrix}\end{aligned}\tag{2},$

and to rotate about $y$ by $\alpha$ you need

$\begin{aligned}q = \begin{bmatrix}\cos(\tfrac{\alpha}{2})\\\sin(\tfrac{\alpha}{2})\\0\\0\end{bmatrix}\end{aligned}\tag{3}.$

If you have a rotation described by the Euler angles $(\phi, \theta, \psi)$ (in the standard order), then, the corresponding quaternion is

$\begin{aligned} q = \begin{bmatrix} \cos \tfrac{\phi}{2} \cos \tfrac{\theta}{2} \cos \tfrac{\psi}{2} + \sin \tfrac{\phi}{2} \sin \tfrac{\theta}{2} \sin \tfrac{\psi}{2} \\ \sin \tfrac{\phi}{2} \cos \tfrac{\theta}{2} \cos \tfrac{\psi}{2} - \cos \tfrac{\phi}{2} \sin \tfrac{\theta}{2} \sin \tfrac{\psi}{2} \\ \cos \tfrac{\phi}{2} \sin \tfrac{\theta}{2} \cos \tfrac{\psi}{2} + \sin \tfrac{\phi}{2} \cos \tfrac{\theta}{2} \sin \tfrac{\psi}{2} \\ \cos \tfrac{\phi}{2} \cos \tfrac{\theta}{2} \sin \tfrac{\psi}{2} - \sin \tfrac{\phi}{2} \sin \tfrac{\theta}{2} \cos \tfrac{\psi}{2} \end{bmatrix} \end{aligned}\tag{4}.$

If you are rotating your object about an axis described by the vector $u=(u_x, u_y, u_z)\in\mathbb{R}^3$ and by an angle $\alpha$ about that axis, then

$\begin{aligned}q = \begin{bmatrix}\cos(\tfrac{\alpha}{2})\\\sin(\tfrac{\alpha}{2})u\end{bmatrix}= \begin{bmatrix}\cos(\tfrac{\alpha}{2})\\\sin(\tfrac{\alpha}{2})u_x\\\sin(\tfrac{\alpha}{2})u_y\\\sin(\tfrac{\alpha}{2})u_z\end{bmatrix} \end{aligned} \tag{5}.$

Related Question