Rotation matrices can be built by combining basic rotations in X, Y and Z (see Wikipedia), but it’s also possible to describe them by setting values in the matrix directly. I’ve recently found this useful as a quick way to create a matrix to convert from a space where the X and Y axes are flipped.

A rotation matrix can be built using three orthogonal vectors which define the original orientation of the X, Y and Z axes in the new coordinate space.

where \(A\), \(B\) and \(C\) are unit vectors.

For the identity matrix (and hence no rotation), \(A = \begin{pmatrix} 1 & 0 & 0 \end{pmatrix}\), \(B = \begin{pmatrix} 0 & 1 & 0 \end{pmatrix}\) and \(C = \begin{pmatrix} 0 & 0 & 1 \end{pmatrix}\).

# An Example

This only made sense to me after trying a few examples.

Rotating 90 degrees around the X axis results in an orientation where:

- \(X_{orig}\) is the original orientation of the X axis. \(X_{orig}\) is equivalent to X because rotation was around the X axis. \(X_{orig} = \begin{pmatrix} 1 & 0 & 0 \end{pmatrix}\)
- \(Y_{orig}\) is the original orientation of the Y axis. It is now pointing along the new Z axis. \(Y_{orig} = \begin{pmatrix} 0 & 0 & 1 \end{pmatrix}\)
- \(Z_{orig}\) is the original orientation of the Z axis. It is now pointing along the negative Y axis. \(Z_{orig} = \begin{pmatrix} 0 & -1 & 0 \end{pmatrix}\)

Putting these three vectors into the matrix above gives the following rotation matrix:

To verify this, here’s the general matrix for rotation around X, where \(\theta\) is the rotation angle:

Setting \(\theta = 90° \) gives:

Which is the same matrix that we originally created.