Affine transformations are a class of transformations fundamental to modelling objects in three dimensions. This article presents the transformation and inverse transformation matrices for translating, scaling and rotating.
|:||A transformed point with co-ordinates ()|
|:||A point prior to transformation which has co-ordinates ()|
|:||The transformation matrix|
Affine transformations are a cornerstone of three dimensional modelling and are the most common class of transformations used in this arena. Essentially affine transformations are transformations in which ratio’s of distances and collinearity are preserved. For example a midpoint on a given line will remain the midpoint of the line and all points lying on a straight line will remain on the line after a affine transformation is applied.
Affine transformations are typically applied through the use of a transformation matrix M and its inverse M-1. For example to apply an affine transformation to a three dimensional point, P to transform it to point Q we have the following equation.
In expanded form this may be presented as follows remembering that the coordinates of Q are a linear combination of the points P.
To transform point Q back into point P we simply premultiply both sides of the previous equation by the inverse of the transformation matrix M-1 to get the following.
Before diving into the world of affine transformation it is important to recognise the difference between a point and a directional vector. A point is fixed in 3 dimensional space and fully describes a position while a directional vector represents a direction relative to a given point and is typically represented as a point on a unit sphere centred on the origin.
When dealing with affine transformation points are represented as P = (Px, Py, Pz, 1) while vectors are represented as v = (vx, vy, vz, 0). The reasons for this will be evident when considering applying a translation transformation.
The primary affine transformations translation, scaling and rotation are explored in further detail in subsequent sections.
Where multiple transformations are to be performed a single compound transformation matrix can be computed. Therefore for situations where a specific series of affine transformations is repeatedly applied, only a single matrix multiplication is required regardless the number of transformations in the series.
The compound transformation matrix may be calculated by pre-multiplying the first transformation matrix by each subsequent transformation. For example if transformation M1 was performed followed by transformation M2 the compound transformation matrix would be calculated as follows:
A single transformation matrix using this method may represent any number of sequential transformations. Similarly the compound inverse transformation matrix may be determined by post-multiplication by each subsequent transformation as shown in equation below
This simplification can significantly reduce the computational load in applications where a fixed series of affine transformations is applied to numerous points, for example ray-tracing.
Translation simply takes a point from one location to another using an offset vector d = (mx, my, mz) where mx, my and mz are the quantities you want to shift a point along the x, y and z axis respectively.
To preform a translation we simply add the offset vector to the point (Q = P + d) and to perform the inverse translation we simply subtract the offset vector (P = Q - P). As such we would expect the offset vector to reside in the fourth column of the transformation matrix so that it does not directly multiply the coordinates of the point but instead the 1 of the point vector to achieve the desired offset effect. The resulting transformation and inverse transformation matrices for translation may be represented as follows:
Remembering that we treat a directional vector as v = (vx, vy, vz, 0) a translation will have no effect on a vector as the translation components all multiply the 0. This is desired as a directional vector is a direction not an absolute position and therefore should not be translated.
Scaling takes an object and changes its size along the coordinate axis relative to the origin. To perform a scaling transformation each coordinate of a point is multiplied by a scaling factor for each coordinate axis.
For example to scale a point P by Sx, Sy and Sz in the x, y and z coordinate axis respectively we have Q = (SxPx, SyPy, SzPz). The resulting transformation and inverse transformation matrices for scaling may be represented as follows:
If a given scaling factor is negative there will also be a reflection about a coordinate axis. Therefore mirror images of objects may be obtained through applying scaling transformations. If all scaling factors are equal such that Sx = Sy = Sz we have uniform scaling and conversely if the scaling factors are not the same we have differential or ansiotropic scaling.
Rotation takes an object and rotates it about a given axis, through some angle. The most elementary rotations are about the coordinate axis and are referred to as x, y and z-rolls.
These elementary rotations will rotate a point counter-clockwise when looking inwards at the origin from the rotation axis. The affine transformation matrices for the elementary rotations are shown below:
Where c = cos(θ) and s= sin(θ) and θ is the rotation angle in radians.
From the above it is obvious that the inverse transformation is simply a rotation by the same angle in the opposite direction. Therefore to simplify coding instead of using the inverse rotation transformation you can use the rotation transformation with the negative of the rotation angle.
The coding of the rotation transformation may be further simplified still by using a arbitrary rotation transformation matrix as derived by Maillot. This transformation matrix may be used not only to preform elementary rotations as above but can also rotations about an arbitrary axis u.
The details of rotations about an arbitrary axis are outside the scope of this article however its application is best noted by Euler’s rotation theorem which states that any rotation or sequence of rotations about some point is equivalent to a single rotation about some axis through that point.
The prime implementation advantage of using an arbitrary rotation transformation matrix is that it requires only a single method to handle all manner of rotations. This matrix is presented below.
It is important to note that the c and s variables have not only been separated out for presentation purposes but they are very expensive functions to call in terms of computational time and therefore it is advantageous to calculate these values once and repeatedly use the result.
Shearing displaces points along the axis to which the shear is applied by an amount proportional to their signed distance along the axis of shear. Therefore lines that are parallel to the axis of shear will shift their position but maintain their length.
Shear can be applied along all coordinate axis and complex shear transformations can be achieved by applying shear along multiple axis. Shear is slightly more complicated than the previous transformations as instead than using a single transformation factor per coordinate axis (N factors where N is the number of coordinate axis), NN factors may be specified. However this means that the shear along a specific coordinate axis can be a function of the of the distance of a point along all remaining axis.
Shear factors are typically specified in the form where a is the axis shear is being applied and b is the coordinate axis the the factor is being applied to. For example, shearing a 2D point P by along the x axis will give the point . In three dimensions the shear transformation can be described by the following equations:
The resulting transformation and inverse transformation matrices for shearing may be represented as follows: