Geometric Transformations Part II

Homogeneous coordinates & matrix representation of 2D transformations

The previous tutorial offered an introduction to 2D-space coordinates, and how to express an object in a coordinate system via matrices. The present tutorial will build on this information and introduce affine transformations by expressing 2D coordinates using 3 x 3 matrices, and as we will see in the next tutorial 3D coordinates using 4 x 4 matrices.

Transformation classification

So far we have dealt with linear transformations, however, it is worth noting that there are other types:

  1. Euclidean (translation, uniform scale, rotation) – preserve the value of the angles;
    1. Can be classed as rigid body (translation, rotation) when they preserve both distance and angle value;
    2. Can be classed as conformal (translation, rotation, uniform scaling) when they preserve angles.
  2. Affine (Euclidean, non-uniform scale, shearing) – preserve parallel line property;
  3. Isometric – preserve distance;
  4. Projective – preserve lines;
  5. Nonlinear (twist, warp) – straight lines become curved.

Affine transformations and homogeneous coordinates

Recall from the previous tutorial that the expressions corresponding to the 3 types of transformations are as follows:

Figure. a)Translation b)Scaling c) Rotation

Figure 1. a) Translation (expressed as addition). b) Scaling (expressed as multiplication). c) Rotation (expressed as multiplication).

Unlike rotation and scaling, translation is expressed through an addition. This is not consistent if we wish to combine the transforms (matrix composition). If the points were expressed as homogeneous coordinates then all three expressions would be multiplications.

There is another case which calls for homogeneous coordinates – when working with composite transformations, such as the transformation describing the rotation by an arbitrary angle φ around a point (Fig. 2), we actually encompass a translation and a rotation into one transform. The translation is not a linear transformation, which means the transformation it yields cannot be expressed by a 2 x 2 matrix. Together with the linear transform it defines a new class, namely affine. By definition, an affine transformation encapsulates both a linear transformation and a translation. However, this is an elongated version, and affine transformations can be neatly written using homogeneous coordinates.

Figure 2.

Figure 2. Rotation around point P is a composite transform made up of a translation by -P, a rotation, and a translation back by P. a) Initial position. b) Translation to origin. c) Rotation of φ. d) Translation back to initial position.

In order to obtain a one-to-one mapping of all 2D-space vectors on a plane (z = 1) in 3D-space, the expression defining the 2D vectors (x, y) has to be expanded to (x, y, 1) (Fig. 3). The coordinates (x, y, z) of a 3-space vector Ph are called homogeneous coordinates of vector P.


Figure 3. a)  2D-space vector representation of initial point P. b) a 3D vector representing homogeneous point P. c) H represents the 3 x 3 matrix of homogeneous transformation for a point P in 2D space.

For 3D-space the equations for multiplication of 2 x 2 matrices can be easily rewritten as follows:


Figure 4. a) Two matrices A, B in 3D space. b) Multiplication of A and B yields a third matrix, C. Every ij-th element in the matrix is given by the generalised expression.

The new vector u (Fig. 5) in 3-space can be multiplied by a matrix A in the following manner:


Figure 5. a) 3D vector u. b) 3 x 3 matrix A. c) Product of A and u.

Any affine transformation (a composition of a translation matrix with any number of other transformation matrices) can be written as 3 x 3 matrix in homogeneous coordinates (Fig. 6). The product of any two matrices is again a matrix of the same form. It also allows the writing of complex transformations as a sequence of simple ones by simply multiplying matrices to get the result.

Figure 6. a) Point P in homogeneous coordinates, and a homogeneous matrix A. b) Product of the matrix A and point Ph. c) coordinates (x', y') of the new point P'h.

Figure 6. a) Point P in homogeneous coordinates, and a homogeneous matrix A. b) Product of the matrix A and point Ph. c) coordinates (x’, y’) of the new point P’h.

Properties of homogeneous coordinates:

  1. An extra coordinate is added to a point P. Instead of simply having  P(x, y) pair, the point is now defined as P(x, y, W) in 3-space;
  2. Two sets of homogeneous coordinates (x, y, W) and (x’, y’, W’) represent the same point if and only if one is a multiple of the other;
  3.  It is worth noting that at least one of the homogeneous coordinates has to be nonzero. If the W coordinate is nonzero then we can divide through by W to homogenize the vector: (x, y, W) = (x/W, y/W, 1).
  4. When W has a nonzero value, the division generally takes place, and the x/W, y/W coordinates are known as Cartesian coordinates of the homogeneous point.
  5. The points containing a W = 0 are called “points at infinity” and are a rare occurrence in this series of tutorials.
  6. If all the triples representing the same point in 3-space are taken then the result is a line in 3-space. Thus, each homogeneous point represents a line in 3-space. Upon homogenizing the line (dividing by W), a point with coordinates (x, y, 1) is obtained. The collection of homogenized points forms a plane defined by the equation W = 1, (x, y, W)-space.

Considering that points are now represented as three-element column vectors, it follows that the transformation matrices (multiplying a point vector) must also be 3 x 3 in size.

Now we can use a consistent 3 x 3 matrix notation for translation, scaling, and rotation transformations – we are almost there. Let’s investigate.


The translation transformation can be rewritten with the help of homogeneous coordinates (Fig. 7). The initial point P is represented by the set of coordinates (x, y, W), which will undergo a translation by factors d(x, y), and yield a new point P’ (x’, y’, W) as follows:

Figure. Translation 3x3 a) b)

Figure 7. a) Initial point P , final translated point P’, and the translation matrix T. b) The expression encompassing 2D affine translation taking the form of matrix multiplication, and not addition.


Scaling (uniform and non-uniform) can be expressed easily with homogeneous coordinates as seen in Fig. 8. The scaling factors don’t have to be equal (yields non-uniform scaling).

Figure. Scaling 3x3 a) b)

Figure 8. a) The scaling matrix S holding the scale factors for both axes. b) The final scaled point P’ after original point P underwent a scaling transformation (S).


Rotation of a certain value θ around a point P yielding a new point P’ can also be expressed in a similar manner to what we have seen so far from the privous examples with homogeneous coordinates:

Figure. Rotation 3x3 a) b)

Figure 9. a) Final point P’ after orientation R(θ) is applied. b) Expression describing affine rotation around a point.


Affine shearing in 2D can also be expressed through homogeneous coordinates in 3-space. The following diagram illustrates the examples of shearing along X and Y axis in the case of a 2D square. Note that this transformation preserves parallelism of lines, and not the value of angles.

Figure. Shearing of square a) b) c) d) e)

Figure 10. a) Matrix expressing shearing along the X axis. b) Matrix expressing shearing along the Y axis. c) Original square before any shearing is applied. d) New square after shearing along the X axis was applied. e) New square after shearing on the Y axis was applied.

Affine transformations & 2D matrix compositing

The matrices described previously (T, S, R) can be combined into one in order to gain efficiency. Rather than applying a series of transformations one after the other, a single transform matrix will affect a point.The product of rotation, translation and scaling matrices yields an affine transformation. It preserves the parallelism of lines, but not of angle values, or line length.

With this in mind, the diagram from Fig. 1 of this tutorial can be expressed mathematically through matrix composition – translation by P, rotation by φ around P, translation by -P:


Figure 11. Rotation around a point as matrix composition. a) Translation by P, and rotation by a value; both expressed as homogeneous matrices. b) Rotation by φ around P is expressed through matrix composition.

To be continued…
Part III (last part) of this tutorial series will introduce 3D geometric transformations expressed through homogeneous coordinates and 4 x 4 matrices.


Software engineer (computer graphics) & CS PhD Padawan. Interested in game engine dev, GLSL, computer vision, GPGPU, V.E./V.R, algo challenges, & Raspberry Pi dev. When I don't shift bits, I enjoy playing SC2, driving to new places, drawing, and playing guitar.

blog comments powered by Disqus