Rotation Matrices

I originally created this page partly to gain experience embedding LaTeX in WordPress posts and pages, partly to gain experience using LaTeX to render math equations, and partly to document my exploration of rotation matrices. [See my Matrix Rotation and Matrix Magic posts for an overview.]

To my surprise, this turned into one of my most viewed pages. Apparently, lots of other people find the topic as fascinating as I do.

[2023/17/01] So, especially given that people have noticed this page and have been meaning to update it anyway, I finally got myself a Round Tuit. Added some stuff and moved the quantum gate stuff to the Quantum Qubit Math page.

Note: The following assumes the reader understands the basic idea that matrices transform a vector into a new vector. Therefore, they transform all the points of a vector space. This page only addresses matrices that rotate the space.


2D

As possibly the simplest example of a transformation matrix, let’s start with a 2D identity matrix:

\displaystyle{I}^{2}=\begin{bmatrix}{1}&{0}\\[0.4em]{0}&{1}\end{bmatrix}

We call it because it’s the identity matrix for two dimensional transformations. Specifically, it’s the no-change transformation in two dimensions. It changes all vectors into themselves.

The trick is to view a transformation matrix as consisting of vertical column vectors, one for each basic axis.

In the two-dimensional case there are two vertical column vectors, usually called i-hat and j-hat. These start off as unit vectors along the X-axis and Y-axis. They are initially identical to x-hat (1,0) and y-hat (0,1), the unit vectors that define the axes. (The “hat” symbol denotes a unit vector.)

\displaystyle{M}=\begin{bmatrix}\,\hat{i}_{x}&\hat{j}_{x}\\[0.6em]\,\hat{i}_{y}&\hat{j}_{y}\end{bmatrix}

The four matrix values, seen as two column vectors, specify where i-hat and j-hat end up. That’s the key. The matrix values determine how those two vectors get transformed. The matrix values are the new values for those vectors. (That’s why we don’t use x-hat and y-hat, which might have seemed like obvious choices. Those vectors define the axes and can’t change.)

So, a matrix describes a transformation of a space, in this case the 2D plane. Such a transformation might be a scaling, a rotation, a shear, or some combination. Notably, in all cases, the origin stays the same.

In the case of the identity matrix, i-hat is (1,0) and j-hat is (0,1), which is exactly where they started. That’s what makes the identity matrix the identity matrix. Nothing changes.

A 2D rotation matrix looks like this:

\displaystyle{R}_{xy}^{2}(\theta)=\begin{bmatrix}\cos\theta&-\sin\theta\\[0.4em]\sin\theta&\cos\theta\end{bmatrix}

The name, {R}_{xy}^{2}(\theta) identifies it as a Rotation matrix. The superscript indicate that it’s a rotation in two dimensions, and the subscript that the rotation involves the X and Y coordinates (exactly as we’d expect in two dimensions). Also, note that R is a function that requires an input, the angle theta (θ).

The result is a matrix with four values based on the sine and cosine of θ. Given the following table, it’s easy to plug in values for four well-known cases of angle θ:

90° 180° 270°
sin θ 0 +1 0 -1
cos θ +1 0 -1 0

So, plugging in the values from the first colum, the first rotation matrix, a rotation of zero degrees, looks like this:

\displaystyle{R}_{z}^{2}(0)=\begin{bmatrix}{1}&{0}\\[0.5em]{0}&{1}\end{bmatrix}

Which is the identity matrix. A rotation of zero degrees does nothing.

The other three matrices for the table values look like this:

{R}_{xy}^{2}(90)= \begin{bmatrix}0&-1\\+1&0\end{bmatrix} {R}_{xy}^{2}(180)= \begin{bmatrix}-1&0\\0&-1\end{bmatrix} {R}_{xy}^{2}(270)= \begin{bmatrix}0&+1\\-1&0\end{bmatrix}

Of course, other angles result in different (non-integer) values.

For instance, a 10-degree rotation matrix looks like this:

\displaystyle{R}_{xy}^{2}(10)=\begin{bmatrix}{+0.9848}&{-0.1736}\\[0.6em]{+0.1736}&{+0.9848}\end{bmatrix}

The values are just cos(10°) and sin(10°) plugged into their appropriate spots.


3D

Here’s the 3D identity matrix:

\displaystyle{I}^{3}=\begin{bmatrix}{1}&{0}&{0}\\[0.5em]{0}&{1}&{0}\\[0.4em]{0}&{0}&{1}\end{bmatrix}

As with the  matrix, we call this because it’s the identity matrix for three dimensions. Also as in 2D, the identity matrix is the null (or zero-degree) transformation for 3D rotation. Applying it to a vector transforms the vector into itself.

In 3D we add a third transformation vector, k-hat, which conceptually starts off as identical to z-hat, the unit vector defining the Z-axis. We also need a third component for all three vectors:

\displaystyle{M}=\begin{bmatrix}\,\hat{i}_{x}&\hat{j}_{x}&\hat{k}_{x}\\[0.6em]\,\hat{i}_{y}&\hat{j}_{y}&\hat{k}_{y}\\[0.6em]\,\hat{i}_{z}&\hat{j}_{z}&\hat{k}_{z}\end{bmatrix}

As before, the trick is that the imagined transformation vectors (in this case i-hat, j-hat, and k-hat) start identical to the basis unit vectors and are transformed to the values given by the matrix.

Here’s the matrix for 3D rotation involving the X and Y coordinates:

\displaystyle{R}_{xy}^{3}(\theta)=\begin{bmatrix}\cos\theta&-\sin\theta&{0}\\[0.6em]\sin\theta&\cos\theta&{0}\\[0.6em]{0}&{0}&{1}\end{bmatrix}

It’s obviously similar to the {R}_{xy}^{2} matrix — we’ve just added the Z-axis. In fact, although the X and Y coordinates are the ones that change, the rotation is actually around the Z-axis. This is also true in the 2D case above, but in two dimensions the Z-axis vanishes into the origin, so rotation in 2D is around the origin (one can imagine a Z-axis sticking out of the 2D plane).

The three matrices for XY rotations of 90°, 180°, and 270° look very much like the three 2D ones above:

{R}_{xy}^{3}(90)= \begin{bmatrix}0&-1&0\\+1&0&0\\0&0&+1\end{bmatrix} {R}_{xy}^{3}(180)= \begin{bmatrix}-1&0&0\\0&-1&0\\0&0&+1\end{bmatrix} {R}_{xy}^{3}(270)= \begin{bmatrix}0&+1&0\\-1&0&0\\0&0&+1\end{bmatrix}

The difference being the identity value in the lower-right corner. This represents that the coordinates on the Z-axis do not change.

Here’s the matrix for 3D rotation involving the X and Z coordinates (in other words, around the Y-axis):

\displaystyle{R}_{xz}^{3}(\theta) = \begin{bmatrix}\cos\theta&{0}&-\sin\theta\\[0.6em]{0}&{1}&{0}\\[0.6em]\sin\theta&{0}&\cos\theta\end{bmatrix}

And here are the three matrices for XZ rotations of 90°, 180°, and 270°:

{R}_{xz}^{3}(90)= \begin{bmatrix}0&0&-1\\0&+1&0\\+1&0&0\end{bmatrix} {R}_{xz}^{3}(180)= \begin{bmatrix}-1&0&0\\0&+1&0\\0&0&-1\end{bmatrix} {R}_{xz}^{3}(270)= \begin{bmatrix}0&0&+1\\0&+1&0\\-1&0&0\end{bmatrix}

Similar to the XY rotation matrices above, but with the four “rotator” values distributed to different cells. The x-hat values are the same, but the z-hat values now rotate and y-hat keeps the Y-axis coordinate values fixed.

Finally, here’s the matrix for 3D rotation involving the Y and Z coordinates (rotating around the X-axis):

\displaystyle{R}_{yz}^{3}(\theta)=\begin{bmatrix}{1}&{0}&{0}\\[0.6em]{0}&\cos\theta&-\sin\theta\\[0.6em]{0}&\sin\theta&\cos\theta\end{bmatrix}

The three matrices for X-axis rotations of 90°, 180°, and 270° are:

{R}_{yz}^{3}(90)= \begin{bmatrix}+1&0&0\\0&0&-1\\0&+1&0\end{bmatrix} {R}_{yz}^{3}(180)= \begin{bmatrix}+1&0&0\\0&-1&0\\0&0&-1\end{bmatrix} {R}_{yz}^{3}(270)= \begin{bmatrix}+1&0&0\\0&0&+1\\0&-1&0\end{bmatrix}

The instances for specific rotations look much like the ones shown above.


4D

Here’s the 4D identity matrix:

I^4=\begin{bmatrix}1&0&0&0\\0&1&0&0\\0&0&1&0\\0&0&0&1\end{bmatrix}

The naming pattern should be familiar by now.

Here’s the matrix for 4D rotation around the Y and Z axes:

R_{yz}^4(\theta) = \begin{bmatrix}\cos\theta&0&0&-\sin\theta\\0&1&0&0\\0&0&1&0\\\sin\theta&0&0&\cos\theta\end{bmatrix}

This is the tesseract rotation that seems to move the cubes along the X-axis (the first mode of rotation seen in the video).

The dual-axis rotation allows rotation of all orientations of cubes in 4D space.

In a tesseract, the four cubes with extent in X or W shift between extending in those axes, while the other four cubes (who have both X and W extent), rotate around either their Y or Z axis (depending on which they have).

In a (3D) cube, 4D rotation rotates the X extent into the W dimension and back (reversed), which allows “flipping” a cube. Consider the above matrix in 3D (no W axis):

R_{x}^3(\theta) = \begin{bmatrix}\cos\theta&0&0\\0&1&0\\0&0&1\end{bmatrix}

This truncated version shifts the X extent into the W dimension, but that dimension is cut off and not shown. The effect is that the X dimension reduces to zero (at 90°), restores in the negative (reversed) direction (at 180°), reduces to zero (at 270°), and finally restores positively (at 360°).

The matrix for 4D rotation around the X and Z axes:

R_{xz}^4(\theta) = \begin{bmatrix}1&0&0&0\\0&\cos \theta&0&-\sin \theta\\0&0&1&0\\0&\sin \theta&0&\cos \theta\end{bmatrix}

Which is the tesseract rotation that seems to move the cubes along the Y-axis (the second mode of rotation seen in the video).

The matrix for 4D rotation around the X and Y axes:

R_{xy}^4(\theta) = \begin{bmatrix}1&0&0&0\\0&1&0&0\\0&0&\cos \theta&-\sin \theta\\0&0&\sin \theta&\cos \theta\end{bmatrix}

Which is the tesseract rotation that seems to move cubes along the Z-axis (the third mode of rotation seen in the video below).



4 responses to “Rotation Matrices

And what do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: