# Understanding and interpreting the homogeneous transformation matrix in 3D space

link to original article: http://mabulous.com/understanding-and-interpreting-the-homogeneous-transformation-matrix-in-3d-space

[color=rgb(85,85,85)][font=Tahoma]

[color=rgb(85,85,85)][font=Tahoma]

[/font][/color]

[/font][/color]

[color=rgb(85,85,85)][font=Tahoma]

[/font][/color]

[color=rgb(85,85,85)][font=Tahoma]

[/font][/color]

[color=rgb(85,85,85)][font=Tahoma]

[color=rgb(85,85,85)][font=Tahoma]

[/font][/color][color=rgb(85,85,85)][font=Tahoma]

[/font][/color]

[color=rgb(85,85,85)][font=Tahoma]

[/font][/color]

[color=rgb(85,85,85)][font=Tahoma]

[/font][/color]

[color=rgb(85,85,85)][font=Tahoma]

[/font][/color][color=rgb(85,85,85)][font=Tahoma]

[/font][/color][color=rgb(85,85,85)][font=Tahoma]

[/font][/color]

[color=rgb(85,85,85)][font=Tahoma]

[/font][/color][color=rgb(85,85,85)][font=Tahoma]

[/font][/color][color=rgb(85,85,85)][font=Tahoma]

[/font][/color]

[color=rgb(85,85,85)][font=Tahoma]

[/font][/color]

[color=rgb(85,85,85)][font=Tahoma]

### In 3D computer graphics it is common practice to describe positions and directions using

[/font][/color]homogeneous coordinate vectors[color=rgb(85,85,85)][font=Tahoma]### and

[/font][/color]affine transformations[color=rgb(85,85,85)][font=Tahoma]### (scaling, rotating, translating, shearing, or a combination of them) using 4x4 transformation matrices. While explaining certain aspects of these transformation matrices to a colleague, I noted that even though there are many articles available on the web which explain the setup of these matrices, most of them do not point out some very important high-level relations between the numbers in the matrix and the actual transformation they represent in 3D space.

[/font][/color][color=rgb(85,85,85)][font=Tahoma]

After reading this article, you should understand these relations and be able to visualize an affine transformation simply by looking at the raw numbers of the matrix. Without going very general mathematically, this article is a high level discussion and will not explain what matrices are or how to perform computations with them. Before reading on you should:

[/font][/color]- [background=transparent]know what vectors and matrices are[/background]

- 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

[color=rgb(85,85,85)][font=Tahoma]

Most articles about 3D transformation matrices will show you something like this:

[/font][/color][color=rgb(85,85,85)][font=Tahoma]

[color=rgb(85,85,85)][font=Tahoma]

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.

[/font][/color][color=rgb(85,85,85)][font=Tahoma]

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 4x4 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 [color=rgb(255,0,0)][background=transparent]

## [background=transparent]e[/background]

[size=2]x[/background][/color], [color=rgb(51,153,102)][background=transparent]## [background=transparent]e[/background]

[size=2]y[/background][/color], [color=rgb(51,102,255)][background=transparent]## [background=transparent]e[/background]

[size=2]z[/background][/color]:[/font][/color][color=rgb(85,85,85)][font=Tahoma]

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).

[/font][/color][color=rgb(85,85,85)][font=Tahoma]

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:

[/font][/color][color=rgb(85,85,85)][font=Tahoma]

http://mabulous.com/understanding-and-interpreting-the-homogeneous-transformation-matrix-in-3d-space

[/font][/color][color=rgb(85,85,85)][font=Tahoma]

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:

[/font][/color][color=rgb(85,85,85)][font=Tahoma]

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.

[/font][/color][color=rgb(85,85,85)][font=Tahoma]

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:

[/font][/color][color=rgb(85,85,85)][font=Tahoma]

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.

[/font][/color][color=rgb(85,85,85)][font=Tahoma]

If you found this article helpful and want to ask or add something, please do so in the comments!

[/font][/color]
1

Sign in to follow this

Followers
0

## 0 Comments

## Recommended Comments

There are no comments to display.

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account## Sign in

Already have an account? Sign in here.

Sign In Now