Translation Matrix

The short version:

\(
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
t_x & t_y & t_z & 1 \\
\end{bmatrix}
\)

Translation is a simple operation: For a given vertex (position vector) \(v\), just add a vector \(\vec{t}\):

\(
\begin{array}{*3r}
\vec{v} & & v_x & v_y & v_z & v_w \\
\vec{t} & +& t_x & t_y & t_z & t_w \\ \hline
\vec{v^1} & & v_x + t_x & v_y + t_y & v_z + t_z & v_w + t_w
\end{array}
\)

In this example, the component \(t_w\) MUST be zero.

What’s with this W thing, anyway?

The short version: Translation matrices won’t work without a 4th row.

When the W component is one (1), the vector is a position.

When W is zero (0), the vector is a direction and magnitude.

This is important in the example above. If we added two vectors with W = 1, the result would have W = 2. This would cause problems later on.

Also, intuitively, we can see that adding two positions together makes no sense. To translate a vertex, we want to add a direction and magnitude to a position. Adding direction and magnitudes together, however, makes perfect sense.

Now, how do we add translation to our matrix?

If we multiply or position \(v\) by this matrix,

\(
\begin{bmatrix}
v_x & v_y & v_z & v_w
\end{bmatrix}
*
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
t_x & t_y & t_z & 1 \\
\end{bmatrix}
\)

Remember that each component of the new vector is the dot product of the vector with the corresponding column:

\(
\vec{v^1} = \begin{bmatrix} \vec{v}\cdot col_0, \vec{v}\cdot col_1, \vec{v}\cdot col_2, \vec{v}\cdot col_3\end{bmatrix}
\)

Where the dot product is the sum of the products of each component of the operand vectors.

\(
\vec{a}\cdot \vec{b}=a_x * b_x + a_y * b_y + a_z * b_z + a_w * b_w
\)

For the case where \(\vec{col_0} = (1,0,0,t_x)\),

\(\vec{v^1}_x = v_x * 1 + v_y * 0 + v_z * 0 + v_w * t_x\)


Notice the last term: if \(\vec{v}_w\) was zero, \(t_x\) would be multiplied by zero, and the vertex would not be moved.

Removing zero terms, and realizing that, for a position vector, w = 1,

\(\vec{v^1}_x = v_x + t_x\)

Thus, the translation component \(t_x\) is simply added to the x component of the vertex.

The effect is identical for Y and Z.

Why a matrix?

If all this accomplishes is to add a position vector (x,y,z,1) and a direction vector (x,y,z,0), why go through the trouble of using a matrix?

Remember that the power of matrices lies in combination of operations. By concatenating rotation, translation and scale matrices, in any order and any number of times, we can represent complex hierarchies and transformations that would be difficult (though not impossible!) to handle otherwise. Imagine rotating a cube, translating it, rotating it again, translating it, rotating it yet again, then projecting it to get some screen coordinates.

To perform that operation without matrices, we’d need to loop through six different operations – rotate, translate, repeat – to arrive at the final position of the vertex.
That’s what is required for, say, the moon orbiting the earth, which orbits the sun.

When you get into complex systems – index finger tip, we’re looking at:

– t: finger tip
– r: joint
– t: next bone length
– r: joint
– t: next bone length
– r: knuckle
– t: distance to wrist
– r: wrist angle
– t: forearm length
– r: elbow
– t: upper arm (radius) length
– r: shoulder
– t: distance to spine
– r: hips
– r: body orientation
– t: body world position

And that’s before we get into view space or apply a projection.

We can concatenate all of those operations into a single matrix, saving valuable compute cycles on the GPU.