Determining yaw, pitch, and roll from a rotation matrix

It is often convenient to determine the $ \alpha$, $ \beta$, and $ \gamma$ parameters directly from a given rotation matrix. Suppose an arbitrary rotation matrix

$\displaystyle \begin{pmatrix}r_{11} & r_{12} & r_{13}  r_{21} & r_{22} & r_{23}  r_{31} & r_{32} & r_{33}  \end{pmatrix}$ (3.43)

is given. By setting each entry equal to its corresponding entry in (3.42), equations are obtained that must be solved for $ \alpha$, $ \beta$, and $ \gamma$. Note that $ r_{21}/r_{11} = \tan
\alpha$ and $ r_{32}/r_{33} = \tan \gamma$. Also, $ r_{31} = - \sin
\beta$ and $ \sqrt{r^2_{32}+r^2_{33}} = \cos\beta$. Solving for each angle yields

$\displaystyle \alpha = \tan^{-1} (r_{21}/r_{11}) ,$ (3.44)

$\displaystyle \beta = \tan^{-1} \Big(-r_{31} \big/ \sqrt{r^2_{32}+r^2_{33}}\Big) ,$ (3.45)

and

$\displaystyle \gamma = \tan^{-1} (r_{32}/r_{33}).$ (3.46)

There is a choice of four quadrants for the inverse tangent functions. How can the correct quadrant be determined? Each quadrant should be chosen by using the signs of the numerator and denominator of the argument. The numerator sign selects whether the direction will be above or below the $ x$-axis, and the denominator selects whether the direction will be to the left or right of the $ y$-axis. This is the same as the $ \atan2$ function in the C programming language, which nicely expands the range of the arctangent to $ [0,2
\pi)$. This can be applied to express (3.44), (3.45), and (3.46) as

$\displaystyle \alpha = \atan2(r_{21},r_{11}) ,$ (3.47)

$\displaystyle \beta = \atan2\Big(-r_{31},\sqrt{r^2_{32}+r^2_{33}}\Big) ,$ (3.48)

and

$\displaystyle \gamma = \atan2(r_{32},r_{33}).$ (3.49)

Note that this method assumes $ r_{11} \not = 0$ and $ r_{33} \not = 0$.

Steven M LaValle 2020-08-14