One thing that I stuggle regularily with, is the order in which matrices should be multiplied to achieve a specific result. So I decided to get this clear for myself for good and all.
As you know, matrices (at least in our context of 3D graphics) represent transformations. Multiple transformation matrices can be combined using marix multiplication. But since this operation is not commutative, the order of the multiplication is important.
Since matrices represent transformations, they build new coordinate systems, too: These new systems are defined by axis vectors that have been transformed using the matrix. An example will clarify this fact:
In the examples used in this post, I will use a rotation matrix around 30 degrees, because
and
, which is easy to write down and we still stay exact when calculating with it.
Part 1: A single transformation matrix
Given the origin system with the axis vectors
and
, when we rotate these vectors around 30 degrees, we get the vectors
and 
Surprisingly – or more precise: not surprisingly, the axis vectors are exactly the components of the matrix that applies the corresponding transformation!
The system axis
and
are contained in the unit matrix 
The rotated axis
and
are contained in the rotation matrix: 
Not convinced that this is true? Then let us investigate what is happening when we apply the matrix transformation to a concrete point and verify the results visually:
The example point
will be transformed using the identity matrix and the rotation matrix:
You see, the identity matrix keeps the same point and the rotation matrix does the correct rotation as can be seen in a graph: the point is rotated around exactly 30 degrees in mathematical positive direction and that the rotated coordinate system still contains the point with the coordinates (2,3) (shown in green):
Note: The coordinates always stay the same, but only the coordinate system within they are used changes.
So, for single matrices everything is clear: The matrix transforms a point and the matrix columns are the axis vectors of the system defined by the matrix. If the point is transformed, its coordinates change only seen from the origin system – within the transformed system they stay the same.
Now lets look at the concatenation of transformations.
Part 2: Concatenation of two transformation matrices
For this experiment, lets take a rotation matrix R and a translation matrix T.
We get the combined Matrix C using C=R*T. This matrix then contains both transformations: The rotation and the translation within a single matrix.
Using the combined matrix C to transform the point we get:
To compare this, lets transform the point with each single matrix after each other and try this with both orders:
(a) First R, then T:


(b) First T, then R:


Please note: the results we get in (b) are excatly the same as we got from the combined Matrix C above with C being R*T!
You might be surprised, but the order of transformations in (a), although this is the order in which the matrices are multiplied, does not result in the same point as the cumulated matrix C. The reason can be found when we recapture the fact, that matrix multiplications don’t change points, but coordinate systems.
So, R*T means the following: First, rotate the origin system using R – and then, within this rotated system, translate the system using T. This is the difference to the calculation of points shown in (a): There we get transformed points and these points are respective to the origin system (remember: point coordinates stay the same, only the system changes – changed point coordinates mean: We look at them from a different system)!
When the points are then translated, this is done again within the origin system. The translation is completely different as it moves the point within the origin system and not in the rotated one!
It is therefore important to always look at the systems that transformation matrices build: They are multiplied in the natural, obvious order as they are applied.
Example: Create a combined matrix that rotates points by 30 degrees around the point (4,5).
To achieve this, the rotation should happen around the given point, which means we have to move the coordinate system first by applying a transformation matrix T(4,5). Then the rotation should be performed: R(30). Finally we need to undo the translation again, because this was a temporay translation to just change the point of rotation.This is achieved by T(-4,-5).
As a result, we get the combined Matrix C = T(4,5) * R(30) * T(-4,-5)
That is logical, isnt’t it?
I hope this post helps you as much as it helped me writing it and that matrices now lose a bit of their mystery (sorry in case you liked that mistery thingy)

