How is a $4\times 4$ Matrix built (concerning position, translation, scale and rotation)?

I am given to understand that a $4\times 4$ matrix can contain position, translation, scale and rotation, but I don't know where all of these are in the matrix. What I have seen so far is that position are on 11, 22 and 33 and that translation is on 41, 42 and 43, but where do the scale and rotation belong?

migrated from mathematica.stackexchange.comFeb 15 '13 at 20:22

This question came from our site for users of Wolfram Mathematica.

• They are all over the place, think about what transformation would rotate $e_i$ (a standard basis vector) $\phi$ degrees towards $e_j$ for instance – ssch Feb 15 '13 at 20:03

For the simplest case take for instance $e_1=\{1,0,0,0\}$ and $e_3=\{0,0,1,0\}$. Rotating $e_1$ towards $e_3$ by $\theta$ radians in the plane spanned by $e_1,e_3$ it would move along the circle $\cos(t)e_1 + \sin(t)e_3 = \{\cos(t), 0, \sin(t),0\}$

The matrix that does a rotation in that plane looks like:

$$\left( \begin{array}{cccc} \cos (\theta ) & 0 & -\sin (\theta ) & 0 \\ 0 & 1 & 0 & 0 \\ \sin (\theta ) & 0 & \cos (\theta ) & 0 \\ 0 & 0 & 0 & 1 \\ \end{array} \right)$$

Note that it has ones at position $(2,2)$ and $(4,4)$ since anything in the span of $e_2$ and $e_4$ is unaffacted, and the rest behaves just like it does in the $2 \times 2$ case.

Don't think of the diagonals as containing position, for instance take the matrix that has $\{a, b, c, d\}$ on the diagonal and zero elsewhere. When you multiply this matrix with a vector $\{v1, v2, v3, v4\}$ you get a new vector $\{a\ v1, b\ v2, c\ v3, d\ v4\}$ If this is not obvious grab pen and paper and do it So this matrix scales vectors a certain amount in each of the standard basis directions, you can think of it as stretching the entire space by a corresponding amount in each direction.

The same way $$\left( \begin{array}{cc} 2 & 0 \\ 0 & \frac{1}{2} \\ \end{array} \right)$$

Does the following when applied to the points in a circle: So instead think of a matrix as an operator that does something to a vector, if we want to combine the action of two matrices (operators) we can just take the result of the first one and then apply the second operation to that. This way we have just defined a new operator, which we can get in matrix form by simply doing matrix multiplication of the two matrices.

You can combine the rotation in the $e_1,e_3$ plane and the stretching operation. But first you have to know in which order you want to do the things.

If we stretch first the resulting matrix is:

$$\left( \begin{array}{cccc} a \cos (\theta ) & 0 & -c \sin (\theta ) & 0 \\ 0 & b & 0 & 0 \\ a \sin (\theta ) & 0 & c \cos (\theta ) & 0 \\ 0 & 0 & 0 & d \\ \end{array} \right)$$

But if you rotate first and then stretch:

$$\left( \begin{array}{cccc} a \cos (\theta ) & 0 & -a \sin (\theta ) & 0 \\ 0 & b & 0 & 0 \\ c \sin (\theta ) & 0 & c \cos (\theta ) & 0 \\ 0 & 0 & 0 & d \\ \end{array} \right)$$

Hopefully this examples gives you some intuition to why $AB$ often is different from $BA$

• But how would it look if I want to combine it all into 1 matrix? Is that possible? – Friso Feb 15 '13 at 22:05
• @Friso1990 Yes, I updated the question. I suggest you play around with constructing $2 \times 2$ matrices that does some particular actions, once you know how it works for $2 \times 2$ matrices you know how it works for $n \times n$ matrices :) – ssch Feb 15 '13 at 22:46

It depends on how you "apply" the matrix to given points/vectors by multiplication. You can

(A) regard a vector as a "row" and you place it to the left of the matrix when multiplying, or

(B) regard a vector as a column, and place it to the right

These two calculations will give you different results, obviously.

In either case, rotation and scaling are represented by the top left $3\times3$ matrix.

In case (A), the first three elements in the bottom (fourth) row of the matrix represent translations. In case (B), you have to put your translation quantities in the fourth column, instead.

I've only told you about 12 elements of the matrix. You may be wondering what the other 4 are for. They are for "perspective" transformations.

A pretty good reference is shene-notes. He uses convention (B).

I'm not sure if this will help but these are the three elementary rotation matrices :

Around $x$ axis : $R_x = \begin{pmatrix} 1 &0& 0\\ 0&\cos \theta & -\sin \theta \\ 0&\sin \theta & \cos\theta \end{pmatrix}$

Around $y$ axis : $R_y = \begin{pmatrix} \cos\theta &0& \sin\theta\\ 0&1 & 0 \\ -\sin \theta & 0 & \cos\theta \end{pmatrix}$

and around $z$ axis : $R_z = \begin{pmatrix} \cos \theta & -\sin \theta&0 \\ \sin \theta & \cos\theta &0 \\ 0&0&1\end{pmatrix}$

Now, a matrix that contains rotational information and translational information is composed by :

• one of the above matrices or a composition of two or more of these matrices
• a $3\times 1$ vector that contains position/ translational information

Generally it can be written like this :

$\left[\begin{array}{c|c} R & L \\ \hline 0 & 1\end{array}\right]$

where $R$ denotes one $3\times 3$ rotational matrix (see above) and $L$ denotes a translational $3\times 1$ vector with (three coordinates).

One example of usage of these type of matrices is to create homogeneous transform matrices.

You can find some explanations about these matrices here.