# Unlearn rotation matrices as rotations

– Hey, Markus! What format is this head-rotation representation in?

– It is a rotation matrix, I answer. Right handed, z forward through the nose and x through the left ear. Our young newly graduated colleague nods his/her head.

After about 10 minutes I hear my name again.

– Markus…. Eh, what order is it?

– Oh no! You have opened Wikipedia? Haven’t you? I answer in despair from my desk.

It happens time to time that a newly graduated engineer (or summer intern) asks me exactly this question. Almost always with the Wikipedia page open at the screen, which I think is horrible (or even worse, some “Learn OpenGL” tutorial).

I steal take a chair to sit down beside the person. This will take a few minutes, we are going to do something that is harder than learning: we are going to unlearn.

It is interesting, I get no questions, or only very short questions, on Euler angels, Rodriguez rotations and actually only one recurrent question on quaternions. But very often I get questions on rotation matrices. I think it is a bit odd since rotation matrices are very simple in comparison to many other rotation representations. I think a big reason for this is the Wikipedia page. It looks something like this:

$R_x(\theta) = \begin{bmatrix} 1 & 0 & 0 \\ 0 & \cos \theta & -\sin \theta \\ 0 & \sin \theta & \cos \theta \end{bmatrix}$ $R_y(\theta) = \begin{bmatrix} \cos \theta & 0 & \sin \theta \\ 0 & 1 & 0 \\ -\sin \theta & 0 & \cos \theta \end{bmatrix}$ $R_z(\theta) = \begin{bmatrix} \cos \theta & -\sin \theta & 0 \\ \sin \theta & \cos \theta & 0\\ 0 & 0 & 1\\ \end{bmatrix}$ $R = \begin{bmatrix} \cos\alpha\cos\beta & \cos\alpha\sin\beta\sin\gamma - \sin\alpha\cos\gamma & \cos\alpha\sin\beta\cos\gamma + \sin\alpha\sin\gamma \\ \sin\alpha\cos\beta & \sin\alpha\sin\beta\sin\gamma + \cos\alpha\cos\gamma & \sin\alpha\sin\beta\cos\gamma - \cos\alpha\sin\gamma \\ -\sin\beta & \cos\beta\sin\gamma & \cos\beta\cos\gamma \\ \end{bmatrix}$

It talks about rotations. Rotation around different axes and their relation to Euler angles. This can be a bit confusing when working with for example a head pose. You can of course think about rotation matrices as if the head rotates around different axes in different order, but it becomes kind of hard to interpret:

$\begin{bmatrix} -0.9987820 & 0.0348782 & -0.0348995 \\ 0.0283128 & 0.9844193 & 0.1735424 \\ 0.0404086 & 0.1723429 & -0.9842078 \end{bmatrix}$

So to interpret this we need to solve the following equation system:

$\begin{cases} -\sin(\beta) & = 0.0404086 \\ \cos(\beta)\sin(\gamma) & = 0.1723429 \\ \cos(\alpha)\cos(\beta) & = -0.9987820 \end{cases}$

and then we get an “intrinsic rotation whose Tait–Bryan angles are α, β, γ, about axes z, y, x” to visualize in our head.

Its sad because I think rotation matrices are one of the easiest representation to interpret.

Don’t think of them as rotations, think of them as a unit vectors of a new coordinate systems.

We describe where the coordinate system is located related to another coordinate system (where we rotate from), for example from the camera’s coordinate system perspective (z forward, y upwards). The first column of the rotation matrix is the new x-axis expressed in the old coordinate system, the second column is the y-axis and so on. An identity matrix would yield in no rotation since all unit vectors would be the same as the previous coordinate system.

$R = \begin{bmatrix} X_x & Y_x & Z_x \\ X_y & Y_y & Z_y \\ X_z & Y_z & Z_z \end{bmatrix}$

Lets go back to the example with the head expressed in the camera coordinate system and assume the head position is atfront of the camera. So by interpret the previous matrix, we can look at the new z-axis:

$Z_{axis} = \begin{bmatrix} Z_x \\ Z_y \\ Z_z \end{bmatrix} = \begin{bmatrix} -0.0348995 \\ 0.1735424 \\ -0.9842078 \end{bmatrix}$

(Remember that z-axis is where the head’s nose is pointing)

We can quickly see that z-part of the z-axis is almost -1. This means the nose is pointing at the opposite direction as the camera, eg. towards the camera if the person is sitting at front of it.

We can also se that the persons head is rotated a little bit up (positive y component of the z-axis) and is pointing a little bit to the right of the camera (negative x component).

And that’s it! Rotation matrices just describe the unit vectors of a new coordinate system.

– Hey, Markus! How come this matrix is 4x4?

// Markus

HN discussion