# Remembering the (2D) rotation matrix

Since the day I met this cutie, I struggled with it. I always knew that there are some cosines, sines, and one minus but never knew how to place them to that bloody $2\times 2$ square matrix.

Today, I still don't remember how the rotation matrix looks like. I don't want to remember. I don't want to know. So maybe the title is a bit misleading. To be honest, this post is more about deriving the matrix than remembering it. For most, I thought that to get the rotation matrix, I need to see the whole thing with polar coordinates, use one (or more) goniometric identities (I need to derive them because as with everything else I just don't remember it) and maybe after all this tiresome work I obtain the result.

## Little brain method

Now, let's use a little bit of brain, and some knowledge of linear transformations (their matrices) and get this thing sorted much more quickly.

What is the simplest rotation? Of course, it's the $0\degree$ rotation, in other words, the identity.

How does the identity matrix look? That's simple, right? $\begin{bmatrix} 1& 0 \\ 0& 1 \end{bmatrix}$

We know that the rotation matrix is composed of just sines, cosines, and $+/-$ signs and also that $\sin 0\degree = 0,$ $\cos 0\degree = 1.$

Ha! Now, we know what's on the main diagonal — cosines. And what remains for the other diagonal? Sines, of course. But we're not that sure about signs of our sines.

Our matrix now looks like this: $\begin{bmatrix} \cos \alpha& \pm \sin \alpha \\ \pm \sin \alpha & \cos \alpha \end{bmatrix}$

Plus, or minus, that is the question. To answer this question, let's think of $90\degree$-rotation and point with coordinates $[1, 1]$. Because when talking about a rotation we usually mean the counterclockwise one, the resulting point should lie on coordinates $[-1, 1]$. It shouldn't be hard to see that one matrix that does that is $\begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix}.$

If we put this together with the nearly-correct rotation matrix we can work out the signs and get the neat result $\begin{bmatrix} \cos \alpha& - \sin \alpha \\ \sin \alpha & \cos \alpha \end{bmatrix}.$

From here, we can also note another nice property. To get the clockwise rotation, all we need is to swap signs accordingly :).