Post · 13 min read· pp. 76–86

Transformation Matrices

Introduction

This page supplements the previous coordinate transformation page by focusing on the many ways to generate and interpret the transformation matrix, Q{\bf Q}. Remember, one more time, that the transform matrix rotates the coordinate system, not the object.


Quick Review

The transformation matrix, Q{\bf Q}, is used in coordinate transformations of vectors and tensors as follows.

Vectorsv′{\bf v'}==Q⋅v{\bf Q} \cdot {\bf v}
2nd Rank Tensorsσ′\boldsymbol{\sigma'}==Q⋅σ⋅QT{\bf Q} \cdot \boldsymbol{\sigma} \cdot {\bf Q}^T
4th Rank TensorsC′{\bf C'}==Q⋅Q⋅C⋅QT⋅QT{\bf Q} \cdot {\bf Q} \cdot {\bf C} \cdot {\bf Q}^T \cdot {\bf Q}^T

and in tensor notation...

Vectorsvi′v'_i==λijvj\lambda_{ij} v_j
2nd Rank Tensorsσmn′\sigma'_{mn}==λmiλnjσij\lambda_{mi} \lambda_{nj} \sigma_{ij}
4th Rank TensorsCmnop′C'_{mnop}==λmiλnjλokλplCijkl\lambda_{mi} \lambda_{nj} \lambda_{ok} \lambda_{pl} C_{ijkl}

In two dimensions, Q{\bf Q} is

Transforms

{\bf Q} = \left[ \matrix {\;\;\;\cos \theta & \sin \theta \\ -\sin \theta & \cos \theta} \right]

where θ\theta is the angle between the old and new axes. This is simply a special case of the general 3-D case discussed below.

Transformation Matrix Properties

Transformation matrices have several special properties that, while easily seen in this discussion of 2-D vectors, are equally applicable to 3-D applications as well. This list is useful for checking the accuracy of a transformation matrix if questions arise. While a matrix still could be wrong even if it passes all these checks, it is definitely wrong if it fails even one!

- The determinant of Q{\bf Q} equals one. - The transpose of Q{\bf Q} is its inverse. - The dot product of any row or column with itself equals one. Ex: ( (\cos \theta ; {\bf i} + \sin \theta ; {\bf j}) \cdot
code
		 (\cos \theta \; {\bf i} + \sin \theta \; {\bf j})  = 1 \) - The dot product of any row with any other row equals zero.    Ex: \( (\cos \theta \; {\bf i} + \sin \theta \; {\bf j}) \cdot
		 (-\sin \theta \; {\bf i} + \cos \theta \; {\bf j})  = 0 \) - The dot product of any column with any other column equals zero.    Ex: \( (\cos \theta \; {\bf i} - \sin \theta \; {\bf j}) \cdot
		 (\sin \theta \; {\bf i} + \cos \theta \; {\bf j})  = 0 \) | 
{\bf Q} = \left[ \matrix {\;\;\;\cos \theta & \sin \theta \\ -\sin \theta & \cos \theta} \right]
|

Multiplication of Transformation Matrices

Recall from above that the dot product of any two different rows or columns of a transformation matrix is zero, while the dot product of any row or column with itself is one. This can be written in matrix and tensor notation as

Q⋅QT=Iandλikλjk=δij{\bf Q} \cdot {\bf Q}^T = {\bf I} \qquad \qquad \text{and} \qquad \qquad \lambda_{ik} \lambda_{jk} = \delta_{ij}

This shows that the transpose of a transformation matrix is also its inverse.

The general definition of Q{\bf Q}, in 3-D, is

{\bf Q} = \left[ \matrix { \cos(x',x) & \cos(x',y) & \cos(x',z) \\ \cos(y',x) & \cos(y',y) & \cos(y',z) \\ \cos(z',x) & \cos(z',y) & \cos(z',z) } \right]

where (x′,x)(x',x) represents the angle between the x′x' and xx axes, (x′,y)(x',y) is the angle between the x′x' and yy axes, etc.

3-D Reduction to 2-D

So a rotation about the zz-axis means that cos⁡(z′,z)=1\cos(z',z) = 1 because the angle between z′z' and zz remains 0°. Meanwhile, cos⁡(x′,z)=cos⁡(y′,z)=cos⁡(z′,x)=cos⁡(z′,y)=0\cos(x',z) = \cos(y',z) = \cos(z',x) = \cos(z',y) = 0 because the angles between these axes remains 90°.

The angle between x′x' and yy is (90∘−θ)(90^\circ - \theta), and cos⁡(x′,y)=cos⁡(90∘−θ)=sin⁡θ\cos(x',y) = \cos(90^\circ - \theta) = \sin \theta.

Likewise, the angle between y′y' and xx is (90∘+θ)(90^\circ + \theta), and cos⁡(y′,x)=cos⁡(90∘+θ)=−sin⁡θ\cos(y',x) = \cos(90^\circ + \theta) = -\sin \theta.

All of this leads to

{\bf Q} = \left[ \matrix { \;\;\; \cos \theta & \sin \theta & 0 \\ -\sin \theta & \cos \theta & 0 \\ 0 & 0 & 1 } \right]

which reveals the 2-D transformation matrix within the 3-D matrix.

An alternative way of interpreting and generating the transformation matrix is as follows.

{\bf Q} = \left[ \matrix { \left( \matrix{\text{x-comp} \\ \text{of } {\bf i'}} \right) & \left( \matrix{\text{y-comp} \\ \text{of } {\bf i'}} \right) & \left( \matrix{\text{z-comp} \\ \text{of } {\bf i'}} \right) \\ \left( \matrix{\text{x-comp} \\ \text{of } {\bf j'}} \right) & \left( \matrix{\text{y-comp} \\ \text{of } {\bf j'}} \right) & \left( \matrix{\text{z-comp} \\ \text{of } {\bf j'}} \right) \\ \left( \matrix{\text{x-comp} \\ \text{of } {\bf k'}} \right) & \left( \matrix{\text{y-comp} \\ \text{of } {\bf k'}} \right) & \left( \matrix{\text{z-comp} \\ \text{of } {\bf k'}} \right) } \right]

where "x-comp of i′{\bf i'}" means the x-component of the i′{\bf i'} unit vector. Pay close attention here to which terms have primes on them and which don't. Don't confuse this with "the x'-component" because "the x'-comp of i′{\bf i'}" is simply 1. Yet another way to say this is, "the first component of the i′{\bf i'} unit vector in the non-primed reference x,y,zx, y, z coordinate system."


Transformation Webpage

This webpage performs coordinate transforms on 3-D tensors. It also reports the transformation matrix. Try it out. Note that rotations on the webpage are always about global axes, e.g., a rotation in the 1-2 plane will be about the 3-axis.


Successive Rotations - Roe Convention

The 3-D transformation matrix can be viewed as a series of three successive rotations about coordinate axes. There must be dozens of variations of this since any combination of axes can be chosen in any order to rotate about. One popular choice is the so-called Roe convention.

As shown in the figure, it consists of (i) a rotation through angle ψ\psi about the z-axis, then (ii) a rotation of angle θ\theta about the new y-axis (which has already rotated itself due to the first rotation about z), and finally, (iii) a second rotation of ϕ\phi about the now-tilted z-axis.

The Roe convention is very popular despite one key challenge it contains. That is... if θ=0\theta = 0, then ψ\psi and ϕ\phi become indistinguishable and only the sum of the two is what matters.

Roe Coordinate System

\begin{eqnarray} {\bf Q} & = & \left[ \matrix { \;\;\; \cos \phi & \sin \phi & 0 \\ -\sin \phi & \cos \phi & 0 \\ 0 & 0 & 1 } \right] \left[ \matrix { \cos \theta & 0 & -\sin \theta \\ 0 & 1 & 0 \\ \sin \theta & 0 & \;\;\; \cos \theta } \right] \left[ \matrix { \;\;\; \cos \psi & \sin \psi & 0 \\ -\sin \psi & \cos \psi & 0 \\ 0 & 0 & 1 } \right] \\ \\ \\ & = & \left[ \matrix { \;\;\; \cos \psi \cos \theta \cos \phi - \sin \psi \sin \phi & \;\;\; \sin \psi \cos \theta \cos \phi + \cos \psi \sin \phi & -\sin \theta \cos \phi \\ -\cos \psi \cos \theta \sin \phi - \sin \psi \cos \phi & -\sin \psi \cos \theta \sin \phi + \cos \psi \cos \phi & \;\;\; \sin \theta \sin \phi \\ \cos \psi \sin \theta & \sin \psi \sin \theta & \cos \theta } \right] \end{eqnarray}

Even though the rotation angles are applied in ψ,θ,ϕ\psi, \theta, \phi order, the matrices are indeed written in the opposite order: ϕ,θ,ψ\phi, \theta, \psi.

Roe Angles Example

In the figure above, ψ=60∘,θ=30∘,\psi = 60^\circ, \theta = 30^\circ, and ϕ=45∘\phi = 45^\circ. These Roe angles give a coordinate transformation matrix equal to

\begin{eqnarray} {\bf Q} & = & \left[ \matrix { \;\;\; \cos 60^\circ \cos 30^\circ \cos 45^\circ - \sin 60^\circ \sin 45^\circ & \;\;\; \sin 60^\circ \cos 30^\circ \cos 45^\circ + \cos 60^\circ \sin 45^\circ & -\sin 30^\circ \cos 45^\circ \\ -\cos 60^\circ \cos 30^\circ \sin 45^\circ - \sin 60^\circ \cos 45^\circ & -\sin 60^\circ \cos 30^\circ \sin 45^\circ + \cos 60^\circ \cos 45^\circ & \;\;\; \sin 30^\circ \sin 45^\circ \\ \cos 60^\circ \sin 30^\circ & \sin 60^\circ \sin 30^\circ & \cos 30^\circ } \right] \\ \\ \\ & = & \left[ \matrix { -0.3062 & \;\;\; 0.8839 & -0.3536 \\ -0.9186 & -0.1768 & \;\;\; 0.3536 \\ \;\;\; 0.2500 & \;\;\; 0.4330 & \;\;\; 0.8660 } \right] \end{eqnarray}

Going In Reverse - Determining Roe Angles from a Matrix

Suppose you have a transformation matrix populated with values as shown here and would like to know what Roe transformation angles were responsible for producing the matrix.

{\bf Q} = \left[ \matrix { q_{11} & q_{12} & q_{13} \\ q_{21} & q_{22} & q_{23} \\ q_{31} & q_{32} & q_{33} } \right]

The first and easiest step is to look at the q33q_{33} component. It is simply the cosine of θ\theta, so θ=Cos−1(q33)\theta = \text{Cos}^{-1}(q_{33}).

The second step is to determine ψ\psi as follows

q32q31=sin⁡ψsin⁡θcos⁡ψsin⁡θ=sin⁡ψcos⁡ψ=tan⁡ψ{q_{32} \over q_{31}} = { \sin \psi \sin \theta \over \cos \psi \sin \theta } = { \sin \psi \over \cos \psi } = \tan \psi
So

ψ=Tan−1(q32q31)\psi = \text{Tan}^{-1} \left( {q_{32} \over q_{31}} \right)
ϕ\phi is determined in a very similar manner.

q23−q13=sin⁡θsin⁡ϕsin⁡θcos⁡ϕ=sin⁡ϕcos⁡ϕ=tan⁡ϕ{q_{23} \over -q_{13}} = { \sin \theta \sin \phi \over \sin \theta \cos \phi } = { \sin \phi \over \cos \phi } = \tan \phi

So

ϕ=Tan−1(q23−q13)\phi = \text{Tan}^{-1} \left({q_{23} \over -q_{13}} \right)
In summary

ψ=Tan−1(q32q31)θ=Cos−1(q33)ϕ=Tan−1(q23−q13)\psi = \text{Tan}^{-1} \left( {q_{32} \over q_{31}} \right) \qquad \qquad \theta = \text{Cos}^{-1} \left( q_{33} \right) \qquad \qquad \phi = \text{Tan}^{-1} \left({q_{23} \over -q_{13}} \right)

UNLESS!!!....... θ\theta proves to be very small! In this case, sin⁡θ\sin \theta will be very small and therefore, so will q13,q23,q31q_{13}, q_{23}, q_{31}, and q32q_{32} because all these terms contain sin⁡θ\sin \theta. This can lead to major round-off errors in any such calculations.

Fortunately, the solution for this (θ→0\theta \rightarrow 0) is to recall that ψ\psi and ϕ\phi become indistinguishable from each other. This permits ϕ\phi to be set to zero, and ψ\psi to be computed according to ψ=Sin−1(q12)\psi = \text{Sin}^{-1}(q_{12}).

Example: Roe Angles from Matrix

Let's start with the matrix in the previous example and work backwards.

{\bf Q} = \left[ \matrix { -0.3062 & \;\;\; 0.8839 & -0.3536 \\ -0.9186 & -0.1768 & \;\;\; 0.3536 \\ \;\;\; 0.2500 & \;\;\; 0.4330 & \;\;\; 0.8660 } \right]

Start with the q33q_{33} term to determine θ\theta.

θ=Cos−1(q33)=Cos−1(0.8660)=30∘\theta = \text{Cos}^{-1}(q_{33}) = \text{Cos}^{-1}(0.8660) = 30^\circ

Since θ\theta is not near zero, ψ\psi and ϕ\phi can be computed as follows.

ψ=Tan−1(q32q31)=Tan−1(0.43300.2500)=60∘\psi = \text{Tan}^{-1}\left({q_{32} \over q_{31}}\right) = \text{Tan}^{-1}\left({0.4330 \over 0.2500}\right) = 60^\circ

ϕ=Tan−1(q23−q13)=Tan−1(0.35360.3536)=45∘\phi = \text{Tan}^{-1}\left({q_{23} \over -q_{13}}\right) = \text{Tan}^{-1}\left({0.3536 \over 0.3536}\right) = 45^\circ

So as expected, the original values are recovered: ψ=60∘,  θ=30∘,\psi = 60^\circ, \; \theta = 30^\circ, and ϕ=45∘\phi = 45^\circ.


Rotation About An Axis

Yet another way of specifying the orientation of a transformed coordinate system is through a rotation axis vector, p{\bf p}, and a rotation angle, α\alpha, about the p{\bf p} axis.

In this case, the transformation matrix is written as

Q=cos⁡α  I+(1−cos⁡α)p⊗p+sin⁡α  P{\bf Q} = \cos \alpha \; {\bf I} + (1 - \cos \alpha) {\bf p} \otimes {\bf p} + \sin \alpha \; {\bf P}

with

{\bf P} = \left[ \matrix { \;\;\; 0 & \;\;\; p_3 & -p_2 \\ -p_3 & \;\; 0 & \;\;\; p_1 \\ \;\;\; p_2 & -p_1 & \;\;\; 0 } \right]

Writing the matrix out gives

{\bf Q} = \left[ \matrix { \cos \alpha + (1-\cos \alpha) p^2_1 & (1 - \cos \alpha) p_1 p_2 + \sin \alpha \; p_3 & (1 - \cos \alpha) p_1 p_3 - \sin \alpha \; p_2 \\ (1 - \cos \alpha) p_2 p_1 - \sin \alpha \; p_3 & \cos \alpha + (1-\cos \alpha) p^2_2 & (1 - \cos \alpha) p_2 p_3 + \sin \alpha \; p_1 \\ (1 - \cos \alpha) p_3 p_1 + \sin \alpha \; p_2 & (1 - \cos \alpha) p_3 p_2 - \sin \alpha \; p_1 & \cos \alpha + (1-\cos \alpha) p^2_3 } \right]

As usual, this can be written quite concisely in tensor notation

Qij=cos⁡α  δij+(1−cos⁡α)pipj+sin⁡α  ϵijk  pkQ_{ij} = \cos \alpha \; \delta_{ij} + (1 - \cos \alpha) p_i p_j + \sin \alpha \; \epsilon_{ijk} \; p_k

It is very important to recognize that p{\bf p} is a unit vector. Using any other length will lead to incorrect results.

Also, it's actually more common to use θ\theta or ϕ\phi as the rotation angle instead of α\alpha. But α\alpha is being used here to minimize confusion with ψ,θ,\psi, \theta, and ϕ\phi used as the Roe convention angles.

It is easy to visualize the coordinate rotations in this method. For example, the 2-D case can be reproduced by noting that the rotation is about the z-axis, so the vector is p=(0,0,1){\bf p} = (0, 0, 1). This leads to

{\bf Q} = \left[ \matrix { \;\;\; \cos \alpha & \sin \alpha & 0 \\ -\sin \alpha & \cos \alpha & 0 \\ 0 & 0 & 1 } \right]

As with the Roe angles, it is possible to back-out p{\bf p} and α\alpha given a transformation matrix, Q{\bf Q}. The first step is to determine α\alpha. This is done by taking the trace of the matrix.

α=Cos−1{12[tr(Q)−1]}\alpha = \text{Cos}^{-1} \left\{ {1 \over 2} \Big[ \text{tr}({\bf Q}) - 1 \Big] \right\}

Once α\alpha is determined, the components of p{\bf p} are computed by

p1=q23−q322sin⁡αp2=q31−q132sin⁡αp3=q12−q212sin⁡αp_1 = { q_{23} - q_{32} \over 2 \sin \alpha } \qquad \qquad p_2 = { q_{31} - q_{13} \over 2 \sin \alpha } \qquad \qquad p_3 = { q_{12} - q_{21} \over 2 \sin \alpha }

The three equations can be conveniently summarized in tensor notation as

pi=ϵijk qjk2sin⁡αp_i = { \epsilon_{ijk} \, q_{jk} \over 2 \sin \alpha}

Note that p{\bf p} becomes undefined when α=0\alpha = 0. This means, "the axis you rotate about doesn't matter if you don't rotate in the first place."

Backing Out P and α

Determine the single rotation, p{\bf p} and α\alpha, that is equivalent to that produced by the Roe angles used earlier: ψ=60∘,θ=30∘,\psi = 60^\circ, \theta = 30^\circ, and ϕ=45∘\phi = 45^\circ.

Recall that the Roe angles ψ=60∘,θ=30∘,\psi = 60^\circ, \theta = 30^\circ, and ϕ=45∘\phi = 45^\circ lead to

{\bf Q} = \left[ \matrix { -0.3062 & \;\;\; 0.8839 & -0.3536 \\ -0.9186 & -0.1768 & \;\;\; 0.3536 \\ \;\;\; 0.2500 & \;\;\; 0.4330 & \;\;\; 0.8660 } \right]

Solving for α\alpha gives

α=Cos−1{12[−0.3062−0.1768+0.8660−1]}=108∘\alpha = \text{Cos}^{-1} \left\{ {1 \over 2} \Big[ -0.3062 - 0.1768 +0.8660 - 1 \Big] \right\} = 108^\circ

Solving for p{\bf p} gives

\begin{eqnarray} p_1 &=& \;\;\; { 0.3536 - 0.4330 \over 2 \; \sin 108^\circ} &=& -0.0417\\ \\ p_2 &=& { 0.2500 - (-0.3536) \over 2 \; \sin 108^\circ} &=& \;\;\; 0.3173\\ \\ p_3 &=& { 0.8839 - (-0.9186) \over 2 \; \sin 108^\circ} &=& \;\;\; 0.9475 \end{eqnarray}

So the Roe angles ψ=60∘,θ=30∘,\psi = 60^\circ, \theta = 30^\circ, and ϕ=45∘\phi = 45^\circ are equivalent to a single rotation of 108∘108^\circ about the axis given by p=(−0.0417{\bf p} = (-0.0417, 0.31730.3173, 0.9475)0.9475). Both sets lead to the new x′,y′,z′x', y', z' axes pointing in the same directions.

The above example closes the loop on converting rotations from one system, Roe, to a second system, about an axis. In this case, and any other, the transformation matrix Q{\bf Q} is the go-between permitting the conversion. The procedure is always to calculate the Q{\bf Q} matrix in the first system and then back-out the angles in the second system from Q{\bf Q}.


Inverses and Transposes

All coordinate transformation matrices possess a rather remarkable property - their transpose is their inverse. So it becomes trivial to compute the inverse of such a matrix.

QT=Q−1soQT⋅Q=I{\bf Q}^T = {\bf Q}^{-1} \qquad \text{so} \qquad {\bf Q}^T \cdot {\bf Q} = {\bf I}

Transpose Product Example

The above Q{\bf Q} matrix is

{\bf Q} = \left[ \matrix { -0.3062 & \;\;\; 0.8839 & -0.3536 \\ -0.9186 & -0.1768 & \;\;\; 0.3536 \\ \;\;\; 0.2500 & \;\;\; 0.4330 & \;\;\; 0.8660 } \right]

Multiply it by its transpose to demonstrate that the result is the identity matrix and therefore, its transpose must also be its inverse.

{\bf Q}^T \cdot {\bf Q} = \left[ \matrix { -0.3062 & -0.9186 & 0.2500 \\ \;\;\; 0.8839 & -0.1768 & 0.4330 \\ -0.3536 & \;\;\; 0.3536 & 0.8660 } \right] \; \left[ \matrix { -0.3062 & \;\;\; 0.8839 & -0.3536 \\ -0.9186 & -0.1768 & \;\;\; 0.3536 \\ \;\;\; 0.2500 & \;\;\; 0.4330 & \;\;\; 0.8660 } \right] = \left[ \matrix { 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 } \right]

As hard as this and the previous page have been, there is still much more to tackle. For starters, there is a very similar line of development for rotating objects around in a fixed coordinate system... just the opposite of what we have done here, which was rotating the coordinate system around while the object itself remained fixed. This will be addressed in later sections. We will see that the rotation matrix (no longer a transformation matrix) is just the transpose/inverse of the transformation matrix.