Demystifying Rotation Matrix
How to rotate a vector in R²
A rotation matrix is like a magical tool in the world of Linear Algebra, designed to spin vectors around in space with precision and ease. Imagine you have a vector, a little arrow pointing somewhere in space, and you want to turn it around a certain point, like spinning a key around a keyring. That's exactly what a rotation matrix helps you do.
To see how the rotation matrix emerges, lets start with a vector in R² and try to rotate it along horizontal axis.
Rotating a vector in R²
The figure below shows a vector v in R² that makes the angle a with horizontal axis. Let's say that we want to rotate it ‘b degrees' counter-clock wise along the horizontal axis, which is denoted by v'.

As we can see, the rotation just changes the direction of v and keeps the length(a.k.a ‘magnitude') same.
In R², we can represent the vector v as the ordered tuple (m, n) with first element in horizontal axis, and the second element in the vertical axis. From trigonometry, we know that the coordinates of v=(m, n) can be represented as (||v||.cos(a), ||v||.sin(a)):

So similarly, v' can be represented as (||v||.cos(a+b), ||v||.sin(a+b)):

So our problem is to find a mapping from v to v'. Any vector can be transformed to another vector through matrix multiplication, especially when it comes to rotations. If you have a vector v and you want to transform it to another vector v′ through rotation, then there exists a rotation matrix A that can accomplish this task:

From the equation above, it seems to be a good idea to represent v and v' as vectors to do some calculations with them. The vector representation of v is as follows (the first element is horizontal and the second element is vertical axis):

Similarly, the vector representation of v' is as follows:

So we have v and v' as vectors. We don't know the elements of the rotation matrix A yet, so lets denote them by variables x, y, z, and t:

By doing matrix vector multiplication on the left hand side and then by equating it to the expressions on the right hand side, we can easily get the values of x, y, z, and t:

So this gives us a rotation matrix as follows:

This is the rotation matrix that we need to rotate any vector v b degrees counter-clock wise along the horizontal axis. Looks cryptical? Let's explore it further.
Properties of Rotation Matrix in R²
Let's explore some special cases to justify the rotation matrix.
0-degree rotation
A 0-degree rotation means that the object or vector is not rotated at all; it stays in its original position and orientation. In terms of transformation matrices, a 0-degree rotation can be represented by the identity matrix. This result makes sense because a 0-degree rotation should not change the vector's position or orientation.

180-degree rotation
A 180-degree rotation means that the object or vector is rotated half a circle from its original position. For a 2D vector, this rotation will flip the vector to the opposite quadrant, changing both its x and y components to their negatives. This result makes sense because a 180-degree rotation should flip the vector to the opposite direction. For instance, if you have a vector pointing straight up, a 180-degree rotation would flip it to point straight down.

First β degree, then –β degree rotation
When a vector undergoes a rotation by an angle β and then undergoes another rotation by an angle –β, the two rotations effectively cancel each other out, resulting in the vector returning to its original position and orientation.
Since there will be two matrix multiplication, one for β and the other for -β degree rotation, it is equivalent to multiply v by a matrix A':

When we calculate the A', we end up with an identity matrix! So A' ⋅ v is equal to v itself! The key for the calculations below is that cosine is an even function and sine is an odd function. So cos(-b) = cos(b), and sin(-b) = -sin(b):

What about R³ ?
The general concept of rotation using matrices can indeed be extended from 2D to 3D and even beyond, to higher-dimensional spaces.
In 2D, a rotation matrix can be used to rotate a vector around the origin. The rotation matrix depends on the angle of rotation, and it transforms the original vector to a new position while preserving its length.
When we move to 3D, the idea is similar, but we have to consider rotations around different axes. In 3D space, you can rotate a vector around the x-axis, y-axis, or z-axis. For each type of rotation, there is a corresponding rotation matrix. Just like in 2D, the length of the vector is preserved during the rotation.
Here's a simplified breakdown:
- Rotation around the x-axis: The y and z components of the vector change, but the x component stays the same.
- Rotation around the y-axis: The x and z components of the vector change, but the y component stays the same.
- Rotation around the z-axis: The x and y components of the vector change, but the z component stays the same.
The rotation matrices for 3D rotations take into account the angle of rotation and the axis of rotation. When you multiply a vector by one of these rotation matrices, you get a new vector that has been rotated around the specified axis by the specified angle.
The same logic applies: if you rotate a vector and then rotate it back by the same angle in the opposite direction (using the inverse rotation), you end up back at the original vector.
This idea can be extended to higher dimensions as well, though visualizing rotations becomes more complex as you move beyond 3D. In any dimension, the concept of using matrices to perform rotations and the properties of these rotations (such as preserving the length of the vector) remain consistent.
Unless otherwise noted, all images are by the author.