- know what vectors and matrices are
- understand matrix*matrix and matrix*vector multiplications by performing a few of them on paper
- understand what a homogeneous coordinate vector is
- check your fridge (just to be sure)

## The setup of a 3D transformation matrix describing an affine transformation

Most articles about 3D transformation matrices will show you something like this: While this is accurate, the formula above shows how to setup the rotational part of the transformation matrix using Euler angles. Not only are Euler angles evil (avoid them whenever possible), the relatively complex looking formula also obfuscates some much easier to comprehend and much more useful informations that can be read from it – so don’t even try to memorize it. Generally, an affine transformation in 3D space describes how to map the coordinates of any point from reference space A to reference space B and we represent this transformation using the 4×4 matrix T. So, if T for example is a “localToWorld” matrix, reference space A would be the local coordinate system (in which for example the vertex coordinates of a 3D mesh are defined) and reference space B would be the world coordinate system. Multiplying any local vertex coordinates with the localToWorld matrix thereby yields the coordinates of said vertex in world space and as such, T describes exactly how the 3D mesh is positioned, oriented and scaled in world space. The transformation is said to span A as a subspace of B, and it does so using the 3 basis vectors ex, ey, ez: And here’s the catch: you can read these three basis vectors as well as the translation component directly from the 4 columns of the transformation matrix. They are expressed in terms of the target space the matrix maps to (so, in world space for the case of a localToWorld matrix). Here is a sample application to illustrate this (you need to have the Unity3D Webplayer installed). Use the mouse to rotate, translate and scale the 3d model and observe how the values in the transformation matrix change. Also you can hover with the mouse over the transformation matrix to get some tool-tips:

In the start configuration the transformation of the 3D mesh is aligned with the world coordinate system, which is why the three basis vectors of the transform equal the basis vectors of the world coordinate system. Rotate the model by about 45° around the Z axis by dragging at the blue circle and you may see something like this: So, visualizing this transformation by looking at the numbers does not require too much imagination anymore. The first column is your thumb, oriented in world space direction (0.7, 0.7, 0.0). The second column is your index finger, oriented in world space direction (-0.7, 0.7, 0.0). The third column is your middle finger, oriented in world space direction (0.0, 0.0, 1.0). The fourth column is the offset from the world origin to the base of your hand and since this example shows a left handed coordinate system, use your left hand to perform this exercise. You can also scale the model by dragging one of the small circles. Observing the numbers in the matrix, you can see that scaling simply means changing the magnitude (length) of the basis vectors. The three numbers below the matrix show these magnitudes: Finally, this article covered a Left Handed 3D space that follows a column vector convention (which is the case for example for Unity3D). If your 3D package assumes row vectors (which is the case for example in XNA), the matrix needs to be transposed. So instead of columns, you would read the rows of the matrix to find the basis vectors. More on 3D space orientation, column vs. row vectors and column major vs. row major matrices will be posted soon. If you found this article helpful and want to ask or add something, please do so in the comments! Matthias Bühlmann

Thanks for the great explanation 🙂

when i studied this, they told us how to calculate this matrix but not how to visualize it.