# 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:

- Euclidean (translation, uniform scale, rotation) – preserve the value of the angles;
- Can be classed as rigid body (translation, rotation) when they preserve both distance and angle value;
- Can be classed as conformal (translation, rotation, uniform scaling) when they preserve angles.

- Affine (Euclidean, non-uniform scale, shearing) – preserve parallel line property;
- Isometric – preserve distance;
- Projective – preserve lines;
- 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:

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.

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 *P _{h}* are called

*homogeneous*

*coordinates*

*of vector P.*

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

The new vector *u ( Fig. 5) * in 3-space can be multiplied by a matrix

*A*in the following manner:

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.

**Properties of homogeneous coordinates:
**

- 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; - 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; - 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)*. - 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. - The points containing a
*W = 0*are called “points at infinity” and are a rare occurrence in this series of tutorials. - 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.

**Translation**

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:*

**Scaling**

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

**Rotation**

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:

**Shearing**

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.

**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*:

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