<<

The Affine of Transformations

Kenneth H. Carpenter Department of Electrical and Computer Engineering Kansas State University

February 26, 1997 (revised September 20, 2001)

1 Introduction

The affine group is a of transformations in space that leave straight lines as straight lines. (These can be thought of as transformations of the coordinate system, leaving the objects unchanged, or as transformations of the objects, leaving the coordinate system unchanged. We shall take the latter viewpoint, since it is the one most closely associated with .) Since one such transformation followed by another results in straight lines going to straight lines going to straight lines, the result of two affine transformations in succession is a third affine transformation. Further, one can reverse any such transformation, to get back to the original lines, so each affine transformation has an inverse transformation. This is all that is required to form a group in mathematics: • set of objects: the transformations themselves • equivalence relation: two transformations are equivalent if they each transform any specific into the same new line • operation: performing first one transformation then another yields a third • satisfies the group postulates: If a, b, c,... are group members and is the operation, then 1. Closure: a b = c (result of operation is in the set - true for affine transformations) 2. Identity: There is an element i such that a i = a for all a (the identity transformation is to do nothing!) 3. Inverses: For every a there must be a b such that a b = i (true for affine transformations - just reverse what was done) 4. Associativity: a (b c) = (a b) c (This is not as obvious, but will be shown later to be true for affine transformations.) Since affine transformations form a group, group theory shows that there exist matrix representations for the group – that is, there is a group of matrices that follows the same rules as the group, with the matrices being the group members, and the operation being . We will find and use one or more of these representations.

2 The of affine transformations

Let the usual notation of x, y, z for the rectangular coordinates of points in three-dimensional space be replaced by x1, x2, x3. Then we can refer to a general coordinate as xi where i = 1, 2, or 3. (Note that x3 does not mean x cubed any more! When we want powers of the xi we have to use parentheses like this: (x2)3.)

1 Affine Transformations - K. H. Carpenter - 20SEP01 2

A general transformation of the points of an object replaces the xi representing a point in space with a new set yi related to the original by three functions of three variables:

yi = f i(x j). (1)

We now inquire what restrictions must be placed on these functions for the transformations to be affine. But first we must find a way to represent a straight line.

2.1 Straight lines in parametric form The simplest way to represent a curve in multiple is by a set of parametric equations, one for each : xi = gi(t), (2) where t is the parameter. Now we can take the differential of eq.(2) to obtain dxi = (dgi/dt)dt. For the curve to be a straight line the ratios dxi/dx j must be the same for all t. This will be true if each dgi/dt is a constant for all t. Hence one way we can express the parametric functions of any straight line is

xi = gi(t) = αit + βi. (3)

2.2 Affine transformations in terms of parametric straight lines Since the result of affine transforming a straight line must be another straight line, and since any straight line can be written in the form of eq.(3), the functions of the transformation must yield

f i(α jt + β j) = γit + δi. (4)

Since d f i/dt = γi, f i can contain only first powers of t, and hence only first powers of the x j. We can thus write

i i j X i j i X i j j i y = f (x ) = (r j x ) + s = [r j(α t + β )] + s . (5) j j

i i where the r j and the s are the constants that specify the transformation. i The r j values are not entirely arbitrary. Since the inverse transformation must exist (for the affine transfor- i mations to form a group), the matrix of the r j’s must have an inverse, hence its must be non-zero.

2.3 Affine transformations retain properties As a corollary to affine transformations being linear, parallel lines subject to the same transformation, remain parallel, and lines that are not parallel before transformation are not parallel after. Parallel lines in the parametric form of eq.(3) have the same αi values but different βi values. From eq.(5) and eq.(4) it can be seen that two parallel lines, after the same transformation, will have the same γi values but different δi values and hence be parallel. The proof of the converse is left as an exercise for the reader. Affine Transformations - K. H. Carpenter - 20SEP01 3

3 The group operation – successive transformations

3.1 From the viewpoint of analytic geometry The constants in eq.(5) represent and translations along with possible and reflection. These i i operations are illustrated in chapter 4 of the text by Angel[1]. Let ra j and sa represent the r and s constants for the a transformation; similarly define the constants for the b transformation. Then successive transformations yields a new transformation c where the constants of c are given by

i X i k rc j = rbkra j (6) k i X i k i sc = ( rbk sa) + sb. (7) k

This can be recognized as the component form of matrix multiplication between matrices Rb and Ra along with vectors S a and S b. In general, the R matrix contains scale factors, inversions, and shears, as well as rotations. When a transfor- mation is a pure rotation, then S = 0 and the inverse of R is its transpose. When scaling occurs the determinant of R has a magnitude other than one, and when reflection occurs the determinant of R is negative.

3.2 From the viewpoint of a matrix representation of the group The two sets of constants that make up the R matrix and S vector for a transformation may be combined into a single square matrix T as  R | S    T =   . (8)    0 | 1  The vector S is appended on the right to the matrix R and a fourth row is made up of “zeros” and a single “one” at the lower right. Now Tc = TbTa, and matrix multiplication is isomorphic to successive transformations, with the first transformation being on the right in the product. Since matrix multiplication is associative, we see that the requirement for associativity of the transforma- tions is met.

4

With the defined as the T of eq.(8), it is possible to express the change of coordinates on transformation by a single matrix multiplication, if the vector of coordinates is extended to be the four- dimensional X:  wx1     wx2  X =   , (9)  wx3     w  where w is any non-zero constant. An obvious choice is w = 1. With such a definition for X and a similar one for the vector Y that results from a transformation, we have Y = TX. Affine Transformations - K. H. Carpenter - 20SEP01 4

5 Primitive transformations

Any transformation may be expressed by a product of simpler, primitive transformations. The choice of prim- itive transformations is somewhat arbitrary. In three dimensions, one can show that any rotation is the product of three rotations. Translations can always be separated from rotations. For more general situations, involv- ing scaling and shearing, the choice of primitives is not so simple. In the following it will be shown that any two-dimensional R can be replaced by a sequence of two-dimensional rotations and scalings.

5.1 Repeated transformations leave the R part a product of R parts From eq.(8), one sees the separation of a general transformation matrix into a translation part S and a general- ized rotation part R. If one multiplies together two such matrices, the R part of the product will be the product of the R parts of the two being multiplied. This continues for any number of transformations. The R parts affect the S parts applied earlier, but the S parts have no effect on the final R part. Thus any transformation could have all its primitives consist of R parts only, except for the last one applied.

5.2 Case of shear For a shear primitive, the transformation has a zero S part and a R part that is the identity matrix with one non- diagonal element replaced by a non-zero value. Since shear is inherently two-dimensional, let us consider only a two-by-two matrix of shear and how it may be broken into other two-by-two matrices representing rotations and scalings. The general form of a two-dimensional rotation matrix is " # cos θ − sin θ U(θ) = . (10) sin θ cos θ The general form of a shear along x is " # 1 h W = . (11) 0 1 The general form of a scaling is " # a 0 K = . (12) 0 b

By multiplying out and forming four scalar equations, one can show that it is not possible to find θ1, θ2, a, and b such that W = U(θ1)KU(θ2). It is possible to represent a shear as a sequence of rotations and scalings, however. One must use three scalings and two rotations (of unequal magnitudes). There are several possibilities.√ √ One possible√ choice is W = K1U(π/6)√K2U(−π/4)K3 where the elements of Ki are ai and bi and a1 = 3/ 2, b1 = 1/(h 2), a2 = a3 = 1, b2 = 1/ 3, and b3 = 2h.

5.3 Minimum number of primitives to represent a transformation A general, non-singular, two-by-two matrix can be represented by a product of three two-by-two matrices, where the three are taken from the special cases of pure rotation, scaling, and shear. Specifically

 α −γ  " # √ √  p 2 2   αβ+γδ   2 2 2 2   α + γ 0   1 √  α β  α +γ α +γ     2 2  =  γ   αδ−βγ   α +γ  , (13) γ δ  √ √ α   0 √    α2+γ2 α2+γ2 α2+γ2 0 1 which is a valid expansion of a general matrix into the product of a rotation, a scaling, and a shear. (The determinant of the matrix is not zero by assumption.) Affine Transformations - K. H. Carpenter - 20SEP01 5

Since, from section 5.2, any shear may be represented by products of rotations and scalings, any two- dimensional matrix may be represented by a sequence of rotations and scalings, although there may have to be several rotations and scalings.

5.4 Extension to three dimensions One can show that any three dimensional affine transformation has a matrix form in terms of translation, rota- tion, scaling, and shearing as

 I | S   R | 0   D | 0   H | 0          T =         . (14)          0 | 1   0 | 1   0 | 1   0 | 1  where the vector S contains the three components of a translation, the R 3 × 3 matrix represents a rotation such that RT = R−1 and |R| = 1, the D matrix is diagonal and contains the scalings and reflections, and the H matrix is upper triangular with ones on the diagonal and contains the shearings along the three axes. Since the H matrix may be written as a product of three matrices each having a shear along a single direction, and since each of these single shears may be expressed as the product of three scalings and two rotations, the entire affine transformation may be presented as a set of translations, scalings, and rotations. (The separation of any general matrix into the product of a rotation matrix and an upper is called QR factorization[2].)

6 Conclusions

Any possible affine transformation (an invertible transformation in which all straight lines remain straight lines) may be represented by a matrix, which for three-dimensional space, is 4 by 4, has the last row as three “zeros” followed by a single “one” and otherwise consists of arbitrary real numbers (except for the restriction that the submatrix R made up of the first three rows and columns has an inverse). Any affine transformation can be decomposed into a series of rotations about three axes, translations, and scalings. The rotations are subsets of the R submatrices which have an inverse equal to the transpose and a determinant equal to one. The scalings are subsets of the R submatrices that are diagonal (with negative elements for reflections). The translations are the submatrices S .

References

[1] Edward Angel, Interactive Computer Graphics : A top-down approach with OpenGL, Addison-Wesley, Reading, Massachusetts, 1997.

[2] David Kahaner, Cleve Moler, Stephen Nash, Numerical Methods and Software, Prentice Hall, 1989.