Introduction to Computer Graphics
Lecture 3
2-D Affine Transformations

Don Herbison-Evans
donherbisonevans@yahoo.com

(updated 29 August 2006)

Affine transformations are those for which straight lines stay straight after the transformation.

Basic Transformations

  • Translation x2 = x1 + tx
    y2 = y1 + ty

  • Scaling x2 = ax*x1
    y2 = ay*y1

  • Shear x2 = x1 + sy*y1
    y2 = y1 + sx*x1

  • Reflection
    x2 = -x1
    y2 = y1
    or x2 = x1
    y2 = -y1
    or x2 = -x1
    y2 = -y1

    Note that the last one is actually a rotation through 180 degrees!

  • Rotation x2 = x1*cos(a) + y1*sin(a)
    y2 = - x1*sin(a) + y1*cos(a)

    Unification

    Augment each point to be a 3D row vector by adding a third unit coordinate :

    x = ( x, y, h ), with h = 1

    All 5 transformations can then be performed using a 3x3 array of 9 coefficients

    x2 = m[0][0]*x1 + m[0][1]*y1 + m[0][2]*h1
    y2 = m[1][0]*x1 + m[1][1]*y1 + m[1][2]*h1
    h2 = m[2][0]*x1 + m[2][1]*y1 + m[2][2]*h1

    with m[2][0] = 0; m[2][1] = 0; m[2][2] = 1;
    and the remaining 6 coefficients doing all the work.

    A transformation can then be abbreviated to :

    x2 = x1*M

    A property of this unification is that if

    x2 = x1*M21 and x3 = x2*M32

    then

    x3 = (x1*M21)*M32 = x1*M31 where M31 = M21*M32

    The elements of M31 can be derived from those of M32 and M21 in a simple fashion:

    m31[i][j] = m21[i][0]*m32[0][j] + m21[i][1]*m32[1][j] + m21[i][2]*m32[2][j]

    In mathematics, M is called a matrix , and the combining of two such matrices in this way is called matrix multiplication.

    This is very important for computer graphics. For scenes containing many points being viewed by a series of transformations, each point need only be transformed by one combined matrix instead of a succession of matrices.

    Inverse Transformations

    Each of the 5 basic transformations has an inverse, written M-1 :

  • translation : negate m[0][2] and m[1][2]
  • scaling : invert m[0][0[] and m[1][1]
  • shearing : negate m[0][1] and m[1][0]
  • reflection : the matrix is its own inverse
  • rotation : negate m[0][1] and m[1][0]
  • Note that if M1 = M2-1 then M2 = M1-1

    The product of a matrix with its inverse is called the Unit or Identity matrix :

      ( 1 0 0 )
    I = ( 0 1 0 )
      ( 0 0 1 )

    Similarity Transformations

    In a triple matrix product: if the first and third transformations are the inverse of each other, the the second transformation is said to be undergoing a similarity transformation, eg

  • scaling about rotated axes
  • rotating about a point that is not the origin,
  • Rows versus Columns

    If the vector had been written as a column instead of a row:

      ( x )
    x = ( y )
      ( h )

    then the rows and columns need to be interchanged (transposed) in the previous algebra, and matrices are applied to the left of a vector instead of the right :

    x2 = M*x1

    and matrices are concatenated on the left instead of the right :

    M31 = M32*M21

    A matrix that is the same when its rows and columns are transposed is said to be symmetric.
    For example the matrices for scaling and reflection are symmetric.
    The transpose of a rotation matrix is its inverse.

    ~~~~~~~~~~~~~~~~~~~~~~~~