# Derivation of the 2-D Rotation Matrix

## Table of Contents

\(\newcommand{\mat}[1]{\mathbf{#1}}\) \(\renewcommand{\vec}[1]{\mathbf{#1}}\) \(\newcommand{\e}[1]{\mathbf{e}_{#1}}\)

This document is an extended example for using this literate program. It should be available in both HTML and PDF versions, as well as the Org mode source code.

## Introduction

There are many articles on the Internet (including the rotation matrix
article on Wikipedia) which *state* that the transformation matrix for
a 2-dimensional rotation through an angle \(\theta\) can be expressed as

but few I am aware of show exactly how this matrix can be derived *by
purely algebraic methods*. It is easy to show that this follows from
the standard 2-D rotation transformation (we do that also here), but
that is not very helpful for a student who has not seen how that
transformation itself can be derived. There are websites that try to
show why it is true visually, but that is not mathematically rigorous
and is again unhelpful for students who have difficulty with
visualization (or who have serious sight impairments).

After I wrote the original version of this article, I found another article that explains rotations in basically the same way I did. I have incorporated its use of \(\alpha\) and \(\beta\) for the angles; originally, I used different variables. However, it does not explain how it goes from transformation to matrix, substitutes diagrams for formal notation and descriptions, and shows more intermediate steps than someone who has a good grasp of basic algebra and trigonometry needs. And it references Wikipedia for the trigonometric identities, not even attempting to prove them. So the present document is (for better or worse) a little more formal, self-contained, and less reliant on visual presentations. It is also available in both HTML and PDF formats, unlike the other article (PDF only).

Supposing only knowledge of high school algebra and trigonometry, and some basic facts about vectors and matrices such as matrix multiplication, the 2-D rotation transformation (and its corresponding matrix) can be derived algebraically. A little knowledge of linear algebra, particularly how to derive transformation matrices from linear transformations, would also be helpful. But I try to leave no doubt that the derivation is correct (though a bit mysterious) even for those who know nothing about that subject.

The derivation makes use of two trigonometric identities, which
readers are assumed to have seen (and subsequently forgotten). In the
interest of completeness^{1}, a proof for these identities—making
use of Euler's formula—is provided; but since this is not
particularly relevant to the main result, and some readers may be
sufficiently familiar with this derivation that they do not wish to
see it again, it has been deferred to an Appendix (with another link
at the place where the identities are used).

## Derivation

Suppose we have a vector \(\vec{p} = \langle x, y \rangle = x\e{1} +
y\e{2}\), where \(\e{1} = \langle 1, 0 \rangle\) and \(\e{2} = \langle 0,
1 \rangle\) are the standard basis vectors. The Cartesian \(x\) and \(y\)
coordinates can be rewritten as **polar coordinates** thus:

for some radius \(r\) and angle \(\alpha\) (not necessarily positive nor unique), measured counterclockwise from the positive \(x\)-axis.

We want to rotate it through an angle \(\beta\) (counterclockwise if \(\beta > 0\)). Since a rotation does not change the radius, but only adds to the angle, the final vector will be \(\vec{p'} = \langle x', y' \rangle\) such that

\begin{align*} x' &= r \cos(\alpha + \beta) \\ y' &= r \sin(\alpha + \beta)\tag{2}. \end{align*}We are looking for a \(2\times{}2\) matrix \(\mat{A}\) such that

\begin{equation*} \vec{p'} = \mat{A}\vec{p}\tag{3}, \end{equation*}when both \(\vec{p}\) and \(\vec{p'}\) are expressed in column form. Using the identities

\begin{align*} \cos(\alpha + \beta) &= \cos\alpha \cos\beta - \sin\alpha \sin\beta \\ \sin(\alpha + \beta) &= \sin\alpha \cos\beta + \cos\alpha \sin\beta, \end{align*}which we derive from Euler's formula in the Appendix below, we combine with the equations in \((2)\) to get

\begin{align*} x' &= r \cos\alpha \cos\beta - r \sin\alpha \sin\beta \\ y' &= r \sin\alpha \cos\beta + r \cos\alpha \sin\beta. \end{align*}Substituting \(x\) and \(y\) for their equivalents from \((1)\), and rearranging to put always \(x\) before \(y\), we find that the correct 2-D rotation transformation is

\begin{align*} x' &= x \cos\beta - y \sin\beta \\ y' &= x \sin\beta + y \cos\beta\tag{4}. \end{align*}To put this transformation into matrix form, we need apply it to the standard basis vectors, then label these transformed standard basis vectors as the columns of matrix \(\mat{A}\). For \(\e{1}\) we get

\begin{align*} x' &= 1 \cos\beta - 0 \sin\beta = \cos\beta \\ y' &= 1 \sin\beta + 0 \cos\beta = \sin\beta, \end{align*}and for \(\e{2}\)

\begin{align*} x' &= 0 \cos\beta - 1 \sin\beta = -\sin\beta \\ y' &= 0 \sin\beta + 1 \cos\beta = \cos\beta. \end{align*}Labeling these results as columns of \(\mat{A}\),

\begin{align*} \mat{A} = \begin{bmatrix} \cos\beta & -\sin\beta \\ \sin\beta & \cos\beta \end{bmatrix}. \end{align*}To verify this as an appropriate way to construct \(\mat{A}\), we substitute this matrix and the general vector \(\vec{p}\) (in column form) into the right-hand side of \((3)\), then carry out the matrix multiplication:

\begin{equation*} \begin{bmatrix} \cos\beta & -\sin\beta \\ \sin\beta & \cos\beta \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} = \begin{bmatrix} x \cos\beta - y \sin\beta \\ x \sin\beta + y \cos\beta \end{bmatrix}. \end{equation*}This matches our previous results in \((4)\), so we know that this matrix \(\mat{A}\) is a correct representation of the 2-D rotation transformation. QED

## Appendix

Euler's formula tells us that \(e^{i\theta} = \cos\theta + i\sin\theta\), where \(i = \sqrt{-1}\) is the unit of imaginary numbers. Applying it to \(\theta = \alpha + \beta\), we obtain

\begin{equation*} e^{i(\alpha + \beta)} = \cos(\alpha + \beta) + i\sin(\alpha + \beta). \end{equation*}But since \(e^{i(\alpha + \beta)} = e^{i\alpha} e^{i\beta}\), we also see that

\begin{align*} e^{i(\alpha + \beta)} &= (\cos\alpha + i\sin\alpha)(\cos\beta + i\sin\beta) \\ &= (\cos\alpha \cos\beta - \sin\alpha \sin\beta) + i(\sin\alpha \cos\beta + \cos\alpha \sin\beta). \end{align*}Equating the real and imaginary components of these two expressions for \(e^{i(\alpha + \beta)}\), we obtain the trigonometric identities

\begin{align*} \cos(\alpha + \beta) &= \cos\alpha \cos\beta - \sin\alpha \sin\beta \\ \sin(\alpha + \beta) &= \sin\alpha \cos\beta + \cos\alpha \sin\beta, \end{align*}as desired.

## Footnotes:

^{1}

Not to mention the fact that I have some difficulty remembering the identities myself!