Introduction to Computer Graphics
Lecture 5
3-D Affine Transformations & Projections

Don Herbison-Evans
donherbisonevans@yahoo.com

(updated 8 November 2006)

Basic Transformations

  • Translation x2 = x1 + tx
    y2 = y1 + ty
    z2 = z1 + tz

  • Scaling x2 = ax*x1
    y2 = ay*y1
    z2 = az*z1

  • Shear x2 = x1 + sxy*y1 + sxz*z1
    y2 = y1 + syx*x1 + syz*z1
    z2 = z1 + szx*x1 + szy*y1

  • Reflection x2 = rx*x1
    y2 = ry*y1
    z2 = rz*z1

    where an odd number of rx, ry, & rz = -1;
    otherwise they = +1;

  • Rotation About x axis:
    y2 = y1*cos(a) + z1*sin(a)
    z2 = - y1*sin(a) + z1*cos(a)

    About y axis:
    x2 = x1*cos(b) + z1*sin(b)
    z2 = - x1*sin(b) + z1*cos(b)

    About z axis:
    x2 = x1*cos(c) + y1*sin(c)
    y2 = - x1*sin(c) + y1*cos(c)

    General rotation:
    x2 = r[0][0]*x1 + r[1][0]*y1 + r[2][0]*z1
    y2 = r[0][1]*x1 + r[1][1]*y1 + r[2][1]*z1
    z2 = r[0][2]*x1 + r[1][2]*y1 + r[2][2]*z1

    where the sum of the squares of the r[i][j] of any row or column = 1

    Note that rotations do not commute, eg

    Rx.Ry != Ry.Rx

    Unification

    Augment each point to be a 4D row vector by adding a fourth unit coordinate :

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

    All 5 transformations can then be performed using a 4x4 array of 16 coefficients

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

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

    Projections

  • Orthographic projections: ignore one coordinate: front elevation: ignore z;
    side elevation: rotate 90 degrees about y, then ignore new z;
    plan view: rotate 90 degrees about x, then ignore new z;

  • Isometric Orthographic projection: rotate 45 degrees about y,
    then approximately 32.4 degrees about x

  • Cavalier Oblique projection: x2 = x1 + z1*cos(a)
    y2 = y1 + z1*sin(a)
    with typically a = 30 or 45 degrees;

  • Map Projections (not affine)
  • onto a plane, eg Gnomic,
  • onto a cylinder, eg Mercator,
  • onto a cone, eg Equidistant.
  • Redundancy Problems in Rotations

    A general rotation in 3 dimensions has 3 degrees of freedom, but its rotation matrix has 9 free elements. So after a number of calculations, the accumulated round-off errors can make the matrix bad. This can fixed or avoided by various strategies:

  • renormalisation: choose 3 arbitrary elements and use the orthogonality conditions between rows and columns to generate the rest.
  • reduce to 3 angles using
        (   cb*cc    cb*sc    -sb )
    Rx(a).Ry(b).Rz(c)   =       (   -ca*sc-sa*sb*cc    ca*cc-sa*sb*sc    -sa*cb )
        (   -sa*sc+ca*sb*cc    sa*cc+ca*sb*sc    ca*cb )

    where ca = cos(a), sa = sin(a), cb = cos(b), sb = sin(b), cc = cos(c), sc = sin(c).

    Can have x,y,z in any order, and any angle clockwise or anticlockwise: 48 permutations: all the matrices are different.

  • reduce to a unit quaternion = a rotation by an angle 'a' about an inclined axis u.
    q = cos(a/2) + u*sin(a/2).
    Good for animation.
    Still redundant : 4 quantities but only 3 degrees of freedom

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