Home About Me Notes Galleries Files Links
Cover Programming Maths Odd Bits
Cover Vectors
Cover Primitives Operations Matrix Operations Homogeneous Matrices

Homogeneous Matrices

Pan-Dimensional Trickery

Earlier it was mentioned that translation using matrix multiplication is impossible since translation affects all points in space but matrix multiplication can't transform a vector made of zeros into one that isn't also full of zeros, i.e. the origin is invariant under matrix multiplication.

This limitation would seem to spoil the most useful feature of matrix multiplication, the ability to composite several transformations, including translation into a single matrix.

But wait, There's a trick! All we have to do is move the origin to somewhere where no one will ever find it: In another dimension!

The trick is demonsrtated here for 2D graphics. It's trivial to extend the principle to 3D graphics.

A house in two dimensions
A house drawn in 2D plane
 
This figure exists in a 2D plane. Vertices in this plane are written in the form
x
y
and cane be transformed with 2 × 2 matrices like
.
a  b
cd



Add a dummy dimension, w
Set the plane in a 3D space
Add an extra axis, w and set the original 2D plane at w = 0. The original vertices are now written as
x
y
0
and may be transformed in the usual ways with an augmented (fattened) matrix of the form
.
a  b  0
cd0
001
Now we're ready for the trick…


Push the 2D universe along w by one unit
Move the 2D plane 1 unit
away from the 3D origin
Move the 2D plane to w = 1. The original vertices are now written as
x
y
1
and the augmented transformation matrix above performs the same operations as before. This matrix, however can be modified to add fractions or multiples of w to the x and y components of the transformed vertices. Behold, the homogeneous matrix:
a    b    Tx
cdTy
001
Since all the vertices have w = 1, the net effect of such a modification is to add arbitrary constants to the x and y components of vertices, i.e. translate them.


A shear in 3D can be used to translate in 2D
This shear transformation
translates the 2D plane



The house, translated
The house, translated
Let's demonstrate a simple translation of
.
1
0
Since we're not going to do anything but translate, the 2 × 2 submatrix at the top left is set to identity:
1    0    1
010
001
This matrix is actually a shear matrix with an invariant plane at w = 0. Since the positions of all the vertices of the figure are described as vectors with a w coponent of 1. The net effect is a translation within the 2D plane that contains our figure.

A neat feature of the homogeneous system like this is that a vertex, which has a position but no size or direction is written with a non-zero w, and a vector, which has a size and direction but cannot have a position let alone be translated, is written with a zero for w. Normals and the direction of infinitely distant light sources are examples of such vectors. They are unaffected by the translation component of homogeneous transformation matrices.


The principle of homogeneous coordinates and matrices works equally well with one, two, three or any number of dimensions. All it takes its another dimension.


Computational Efficiency

It might seem that tacking on extra 1s to vectors and multiplying by larger matrices may seem a computational hassle, even if homogeneous matrices do allow the composition of arbitrary numbers of transformations, including translation, If you only plan to perform basic transformations in the w = 1 plane, then you can use Affine matrices. Just chop out all the 0s and 1s and define a kind of matrix multiplication that works with the 2 × 3 matrices that remain. In other words, don't store those 0s and 1s and don't do arithmetic with them.


So Now You Know Everything

This concludes my notes on vector algebra. You should be able to write a killer 3D app now, or at least get some sleep.