# Transformations

Transformations are central in computer graphics. They are used to map from one space to another along the graphics pipeline;

# Affine Transforms

A very good source for affine maps in Gerald Farin's book [Far93], Curves and Surfaces for CAGD: A Practical Approach.'' Some of this introductory material comes from Farin's text.

Let be two points in three dimensional Euclidean space E3. Their difference

is the vector from a to b in the three dimensional linear space R3. Vectors can be added, subtracted and multiplied by constants. (Note the restriction to E3 is not essential: We could generalize to any dimension Em, but three dimensions is most useful for computer graphics.)

Points be subtracted, but addition and scalar multiplication of points is not defined. Points can have a vector added to them to form another point:

This is a translation of point a along vector to point b.

Points determine position; vectors determine direction and magnitude. For any two points a and b there is but one vector from a to b. However, given there are infinitely many pairs of points that determine . Indeed, if and is any vector, then

Now let be n+1 points in E3. And let be n+1 real numbers (weights) that sum to 1. We define the barycentric (or affine) combination of these points to be

This looks like we've invalidated our statement that points can not be added, but the fact that the weights add to one allow us to write the barycentric combination as a point plus the sum of vectors. That is,

An important special case of barycentric combinations are convex combinations. Here we require that the weighs be non-negative () as well as sum to 1.

Note that a weighted sum of points is a vector when the weights add up to zero.

## Affine Maps

A map A that maps E3 into itself is called affine if it leaves barycentric combinations invariant. That is, pretend

is a barycentric combination of points

and A is an affine map. Then

is a barycentric combination of points.

To be more specific, let's think of point p with coordinates . An affine map can be represented in the familiar form

where M is a matrix and is a (translation) vector in R3.

Note that we write point-matrix multiplication with the point on the left of the matrix: This seems common practice in the computer graphics literature. Placing the point on the right is more common in mathematical writing. It is easy to change from one form to the other via the transpose operation. We will write

This is equivalent to

Thus the major difference is: we write points (and vectors) as rows, others write them as columns.

We will see that the useful tranformations: translations, scale, rotation, shear, and parallel projection are all affine maps.

## Linear Interpolation

A particularly useful barycentric combination is linear interpolation. Let be two points and let the weights be 1-t and t for some real number (parameter) t. Then the points

is called the straight line through a and b. The line L(t) is a barycentric combination. If we restrict the parameter t to lie between zero and one ( ), L(t) is a convex combination: It is the line segment from a to b. Note that there is a direction of travel implied along the line.

# Matrices

Matrices are the basic tool that transform (map) points from E3 into E3. A matrix is an array with n rows and m columns. You need to know how to perform matrix multiplication. Most of our matrices will be , but they'll start out as .

Pretending that matrix multiplication is a collection inner products is useful since it provides a geometric interpretation. That is, the element in the product AB is the inner product of the i-th row of A with the j-th column of B. If you are uncertain about inner products, you'll want to read about them.

## Rows and Columns

A row

should be thought of as a point (using our notational conventions). A column

should be thought of as a plane. The inner (or dot, scalar, matrix) product of them

is a scalar (real number). If the value is zero, the point lies in the plane.

## Scales

Scaling alters the size of an object. Pretend you are given a point which is an object vertex, and let be scale factors in , respectively. Then the point can be scaled to a new point by the matrix

In particular,

To scale (enlarge or shrink) the size of an object, each object vertex is multiplied by the scale matrix Sas shown above.

### The Fixed Point of a Scale

Note that the origin is unchanged by a scale (it is still the origin). There is always one fixed point for any scaling operation. By default the fixed point is the origin , but we can select an arbitrary fixed point by the following three step process, which will be more completely defined below.

1.
Translate to
2.
Scale by
3.
Translate to

### The Inverse of a Scale

As long as we do not scale by zero, a scale can always be inverted (undone) by the matrix

The product SS-1= S-1S=I, the indentity matrix.

## Rotations

Rotations alter the orientation of an object: They are a little more complex than scales. Starting in two dimensional rotations is easiest.

### Rotations in Two Dimensions

A rotation moves a point along a cirular path centered at the origin (the pivot). It is a simple trigonometry problem to show that rotating counter-clockwise by radians produces a new point given by

For example, pretend and . Then , which you should agree correctly matches the description.

Of course, we can express the rotation in matrix form

### The Pivot of a Rotation

By default the pivot point is the origin , but we can arrange for an arbitrary pivot by using a three step process similar to the one for scaling about an arbitrary fixed point described about.

1.
Translate to
2.
Rotate by
3.
Translate to

### Rotations in Three Dimensions

In three dimensions points are rotated about an axis, which is a line in three dimensional space. There are three principle axes: the x, y, and z axes. We assume a right-handed coordinate system, with the convention that positive rotation is counter-clockwise.

or in matrix notation

The notations Rz and Rxy are meant to be mneumonics for rotate about z'' and rotate from x toward y.''

or in matrix notation

or in matrix notation

Angles of rotation about the principle axes are called Euler angles.

### Rotation About an Arbitrary Axis

Consider an axis through the origin determined by a unit length direction vector , (the completely arbitrary case will be easily handled after translations are introduced). We can arrange to rotate by theta radians about this axis using a five step process

1.
Rotate into the xz plane, call the result
2.
Rotate into the z axis
3.
4.
Invert the rotation of into the z axis
5.
Invert the rotation of into
This is messy and error-prone when using hand calculation, however, if you carry it out, the result is

 (1)

You should verify that this matrix reduces to rotations about z, x, and y for appropriate choices of the direction vector Below, we'll see that there are better ways to derive this matrix.

### The Inverse of a Rotation

The inverse of a rotation by radians can be created by rotating by radians, but this is not the best way to view it. Consider the trigonometic identities

If you plug these into the arbitrary rotation from equation (1), you'll see that the inverse of R is the transpose of R. This is an important observation.

## Translations

Translations change the position of an object. A pure (three dimensional) translation can not be implemented using a matrix: It is an affine map. We must alter our notion of a point to accommodate translations. A three dimensional point will be embedded in three dimensional homogeneous space and represented as a 4-tuple . For now, the homogeneous coordinate w will have the fixed value 1. This allows us to implement translations using matrices, in particular, the matrix

translated the point into the point .

### The Inverse of a Translation

To undo a translation by use the matrix

We can now complete scaling about an arbitrary fixed point and rotation about an arbitrary pivot. To scale about use the composition of matrices

which when multiplied out yields

So a scaled point becomes
 = (2) = (3)

In a similar manner you can determine that rotation about a pivot results in

## Efficiency of Matrix Multiplication

Now is a good time to mention the fact that it is more efficient, in general, to form one composite transform than to pass a sequence of points through one transform, then another, and another, and so on.

Let's see why this is. Multiplying one point (a 4-tuple) by a transformation ( matrix) costs 16 multiplies and 12 additions. Therefore, transforming an object with n vertices by one transform costs 16n multiplies and 12n additions.

On the other hand, multiplying two matrices costs 64 multiplies and 48 additions. So compositing m matrices together costs 64(m-1) multiplies and 48(m-1) additions.

So consider the alternatives:

1.
Multiply n vertices through a sequence of m transformations at a cost of 16n multiplies and 12n adds per transform. The total cost will be

2.
Form on composite matrix and pass n vertices through it. The total cost will be

# Where Are Transformations Used?

Objects defined in model space can be scaled, translated, and rotated into world space and then viewed from any position. The map from model to world to view is most often concatenated into one single tranform so we map from a model directly into view space without every stopping in the world.

Next we map objects from view space into perspective space. This involves projections: either parallel or perspective. Note that we must stop in view space to compute the illumination that lights bring to our view.

From perspective to clip space and from clip space through normalized space to device space are fairly straight forward scales and translations -- we just need to be careful not to introduce distortions by our scaling of the objects.

# Non-linear transforms

Here we want to describe perspective transforms. They are non-linear, that is, lines do not map into lines. (To be completed)

# Conclusions

## Bibliography

Far93
Gerald Farin.
Curves and Surfaces for Computer Aided Geometric Design.

William D. Shoaff
2002-03-04