I've been doing a lot of research on quaternions, and have been converting to and from 3-2-1 euler angles a lot. I have been using the following source wikipedia as my formula for this conversion.

$$ \begin{bmatrix}q_w \\ q_x \\ q_y \\ q_z \end{bmatrix} = \begin{bmatrix} \cos(\phi/2)\cos(\theta/2)\cos(\psi/2) + \sin(\phi/2)\sin(\theta/2)\sin(\psi/2) \\ \sin(\phi/2)\cos(\theta/2)\cos(\psi/2) - \cos(\phi/2)\sin(\theta/2)\sin(\psi/2) \\ \cos(\phi/2)\sin(\theta/2)\cos(\psi/2) + \sin(\phi/2)\cos(\theta/2)\sin(\psi/2) \\ \cos(\phi/2)\cos(\theta/2)\sin(\psi/2) - \sin(\phi/2)\sin(\theta/2)\cos(\psi/2) \\ \end{bmatrix} $$

and the inverse conversion:

$$ \begin{bmatrix} \phi \\ \theta \\ \psi \end{bmatrix} = \begin{bmatrix} \arctan\left(\frac{2(q_w q_x + q_y q_z)}{1-2(q_x^2 +q_y^2)}\right) \\ \arcsin(2(q_w q_y - q_z q_x)) \\ \arctan\left(\frac{2(q_w q_z + q_x q_y)}{1-2(q_y^2 +q_z^2)}\right) \end{bmatrix} $$

From what I understand, in a typical setup, $\psi$ (yaw) should be the rotation about the $z$-axis of the world frame. Because it happens first, I would suspect that the $\psi$ equation above to equal $0$ if $q_z$ is $0$. Turns out, this is not the case: (If I plug in $0$ for $q_z$ I get the following for the expression for yaw.)

$$ \begin{eqnarray} \psi &= \arctan\left(\frac{2q_x q_y}{1-2q_y^2}\right) \end{eqnarray} $$

This is counter-intuitive to me. Does anyone have any intuition about why this is case?


1 Answer 1


A unit quaternion $q$ representing a rotation of $\theta$ radians around the axis $B$ is:

$q = \cos \frac{\theta}{2} - \sin \frac{\theta}{2} B$

The coordinate $q_w = \cos \frac{\theta}{2} $ while the other three coordinates correspond to $- \sin \frac{\theta}{2} B$.

So the coordinate $q_z$ is not an angle, it is just the z-coordinate of the rotation axis $B$ multiplied by $- \sin \frac{\theta}{2}$.

That means, if you want a quaternion that leave the z-axis invariant to rotation you need a rotation around the z-axis, that is to set $B = [0 \ 0 \ 1]^T$.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .