Given the 'xyz' rotation matrix ($\theta$ - roll, $\phi$ - pitch, $\psi$ - yaw):
$$R = \begin{bmatrix} c_\phi c_\psi & -c_\phi s_\psi & s_\phi \\ c_\theta s_\psi + c_\psi s_\phi s_\theta & c_\psi c_\theta - s_\phi s_\psi s_\theta & -c_\phi s_\theta \\ s_\psi s_\theta - c_\psi c_\theta s_\phi & c_\psi s_\theta + c_\theta s_\phi s_\psi & c_\phi c_\theta \end{bmatrix}$$
where $c_x = \cos x$ and $s_x = \sin x$, we can say that the singularity has occured if $|R(1,3)|-1=0$. In my textbook, the angles are calculated as follows: $$\theta = 0,$$ $$\phi=\arcsin{R(1,3)}$$ and there are two cases for $\psi$:
- If $R(1,3)=\sin\phi=-1$, $\phi=-\pi/2$: $$\psi=-\arctan2(R(2,1), R(3,1))$$
- If $R(1,3)=\sin\phi=1$, $\phi=\pi/2$: $$\psi=\arctan2(R(3,2), R(2,2))$$
What confuses me is the first case. Why is there a minus sign before $\arctan2$?