2D rotations

1. 2D rotations
Rotations in a 2D plane are mostly understood either through a matrix or through complex numbers.
1.1 Matrix representation
A vector \( \begin{bmatrix} r.cos(θ) \\ r.sin(θ) \end{bmatrix} \) when rotated by an angle \( ⍺ \) becomes \( \begin{bmatrix} r.cos(θ+⍺) \\ r.sin(θ+⍺) \end{bmatrix} \). This implies that the rotation matrix is \( \begin{bmatrix} cos(⍺) & sin(⍺) \\ -sin(⍺) & cos(⍺) \end{bmatrix} \). Refer to this article for two different ways to derive this matrix step-by-step.
Grid lines transformed by rotation matrix: \( \begin{bmatrix} 0.87 & -0.5 \\ 0.5 & 0.87 \end{bmatrix} \)
1.2 Complex numbers
A complex number \( z = a + ib \) (where \( i \) is the imaginary number i.e. \( i^2 = -1 \)) can be thought of as an ordered tuple of two numbers a and b. This tuple (a,b) can be used to represent the point \( \begin{bmatrix} a \\ b \end{bmatrix} \) in the 2D plane. Since we know how to multiply two complex numbers, and we know how to visualize a complex number as a 2D vector, we can visualize the multiplication of two 2D vectors.
\( (a + ib).(c + id) = (ac-bd) + i(ad+bc) \)
Now consider a special class of imaginary numbers: \( z = \text{cos(θ)} + i \ \text{sin(θ)} \). Multiplying this with any complex number \( x + iy \) gives:
\( (\text{cos(θ)} + i \ \text{sin(θ)}).(x + iy) = (x\text{cos(θ)}-y\text{sin(θ)}) + i(x\text{sin(θ)}+y\text{cos(θ)}) \xrightarrow{\text{as a vector}} \)\( \begin{bmatrix} x\text{cos(θ)}-y\text{sin(θ)} \\ x\text{sin(θ)}+y\text{cos(θ)} \end{bmatrix} \)\( = \)\( \begin{bmatrix} cos(θ) & -sin(θ) \\ sin(θ) & cos(θ) \end{bmatrix} \)\( \begin{bmatrix} x \\ y \end{bmatrix} \)
Therefore, to rotate any vector \( \begin{bmatrix} x \\ y \end{bmatrix} \) by an angle \( \theta \), we convert the vector into the corresponding complex number \( \text{x} + i\text{y} \), multiply it by the complex number \( \text{cos(θ)} + i \ \text{sin(θ)} \) and then convert the product (which is also a complex number) back to a vector. This is the reason why complex numbers are used to represent rotations in many applications.
1.2.1 Complex exponential
Here we show (not prove) visually that the complex number \( \text{cos(θ)} + i \ \text{sin(θ)} = e^{i\theta} \). Note that \( e^x = 1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} + \ldots \).
Substituting \( x = iθ \) gives \( e^{i\theta} = 1 + i\theta + \frac{(i\theta)^2}{2!} + \frac{(i\theta)^3}{3!} + \ldots \). Let's map the sum of these terms to the complex plane (which is a 2D plane). As we include more and more terms, the sum approaches a point on the unit circle. This point is \( \text{cos(θ)} + i \ \text{sin(θ)} \).
A visualization of the fact that \( \text{cos(θ)} + i \ \text{sin(θ)} = e^{i\theta} \)
The converging sum of: \( \)
Thus, multiplying \( e^{i\theta} \) to a complex number \( x + iy \) is equivalent to rotating the vector \( \begin{bmatrix} x \\ y \end{bmatrix} \) by an angle \( \theta \).
1.3 Number of free variables
A 2D rotation matrix has one free variable. In other words, if we know just one entry of the matrix, we can calculate the rest of the entries. It also aligns with the fact that the complex exponential \( e^{i\theta} \) has one free variable \( \theta \). The number of free variables for rotation in n-dimensional space will come in handy later in this article.