Transformations and Matrices
From Math Images
| Transformations |
|---|
Transformations
- This picture shows an example of four basic transformations (where the original teapot is a red wire frame). On the top left is a translation, which is essentially the teapot being moved. On the top right is a scaling. The teapot has been squished or stretched in each of the three dimensions. On the bottom left is a rotation. In this case the teapot has been rotated around the x axis and the z axis (veritcal). On the bottom right is a shearing, creating a skewed look.
Contents |
Basic Description
When an object undergoes a transformation, it can be represented as a matrix. Different transformations such as translations, rotations, scaling and shearing are represented mathematically in different ways. One matrix can also represent multiple transformations in sequence when the matrices are multiplied together.Linear Transformations Are Matrices
A linear transformation on 2D (or 3D) space is a function f from 2D (or 3D) space to itself that has the property that
Since points in 2D or 3D space can be written as
or
with i, j, and k the coordinate vectors, then we see that
or
This tells us that the linear transformation is completely determined by what it does to the coordinate vectors.
Let’s see an example of this: if the transformation has the following action on the coordinates:
then for any point we have:
From this example, we see that the linear transformation is exactly determined by the matrix whose first column is
, whose second column is
, and whose third column is
, and that applying the function f is exactly the same as multiplying by the matrix. So the linear transformation is the matrix multiplication, and we can use the concepts of linear transformation and matrix multiplication interchangeably.
Transformation Composition Is Matrix Multiplication
Transformations are usually not used by themselves, especially in graphics, so you need to have a way to compose transformations, as in
. But if G is the matrix for the transformation g, and F is the matrix for the transformation f, then the matrix product G*F is the matrix for the composed functions gf.
Basic Transformations For Graphics
Computer graphics works by representing objects in terms of simple primitives (link to the graphics primitives page) that are manipulated with transformations that preserve some primitives’ essential properties. These properties may include angles, lengths, or basic shapes. Some of these transformations can work on primitives with vertices in standard 2D or 3D space, but some need to have vertices in homogeneous coordinates. The general graphics approach is to do everything in homogeneous coordinates, but we’ll talk about the primitives in terms of both kinds when we can.
The most fundamental kinds of transformations for graphics are rotation, scaling, and translation. There are also a few cases when you might want to use shear transformations, so we’ll talk about these as well.
A More Mathematical Explanation
- Note: understanding of this explanation requires: *stacks
Rotation
<span class="_togglegroup _toggle_initshow _toggle _toggler toggle-visible" style="dis [...]Rotation
Scaling
Translation
Shear
Matrix Inverses
Transformations and Graphics Environments
Attention – this concept needs a bit of programming background; it involves stacks.
When you are defining the geometry for a graphics image, you will sometimes want to model your scene as a hierarchy of simpler objects. You might have a desk, for example, that is made up of several parts (legs, drawers, shelves); the drawers may have handles or other parts; you may want to put several things on top of the desk; and so on. It’s common to define general models for each simple part, and then to put the pieces together in a common space, called the “world space.”
Each simple part will be defined in its own “model space,” and then you can apply transformations that move all the parts into the right place in the more complex part. In turn, that whole more complex part may be moved into another position, and so on – you can build up quite complex models this way. One common technique for this kind of hierarchical modeling is to build a “scene graph” that shows how everything is assembled and the transformations that are used in the assembly.
As an example, consider the simple picture of a bunny head, basically made up of several spheres. Each sphere is scaled (making it an ellipsoid of the right size), rotated into the right orientation, and then translated into the proper place. The tree next to the picture shows how this is organized.
In order to make this work, you have to apply each set of transformations to its own sphere and then “forget” those transformations so you can apply the transformations for the next piece. You could, of course, use inverses to undo the transformations, but that’s slow and invites roundoff errors from many multiplications.
instead, it is common to maintain a “transformation stack” that holds the history of every place you want to get back to – all the transformations you have saved. This is a stack of 4x4 matrices that implement the transformations. You also have an active transformation to which you apply any new transformations by matrix multiplication.
To save a transformation to get back to later, you push a copy of the current active transformation (as a 4x4 matrix) onto the stack. Later, when you have applied whatever new transformations you need and want to get back to the last saved transformation, you pop the top matrix off the stack and make it the current active transformation. Presto – all the transformations you had used since the corresponding push operation are gone.
So let’s get back to the rabbit. We want to create the rabbit head, and we have whatever active transformation was in place when we wanted to draw the head. Then we have
- push
- scale
- sphere for main part
- pop
- translate
- scale
- sphere for left eye
- pop
- Translate
- Scale
- sphere for right eye
- pop
- Translate
- Rotate
- Scale
- sphere for left ear
- pop
- Translate
- Rotate
- Scale
- sphere for right ear
- pop
Notice something important: the transformations are written in the order they are applied, with the one closest to the geometry to be applied first. The right ear operations are really Translate(Rotate(Scale(sphere-for-right-ear)))
If you are not familiar with stacks, this won’t make much sense, but this isn’t necessary to understand basic transformation concepts. A simple way to look at these stacks is to notice that a transformation is a 4x4 matrix or, equivalently, a 16-element array, so maintaining a stack is simply a matter of building an array
- float transStack[N][16];
- float transStack[N][16];
or
- float transStack[N][4][4];
- float transStack[N][4][4];
where N is the number of transformations one wants to save.
Teaching Materials
- There are currently no teaching materials for this page. Add teaching materials.
Leave a message on the discussion page by clicking the 'discussion' tab at the top of this image page.




, 
, the axis of rotation. This looks like an exact analogue of the XY-plane, and so we can see that the rotation matrix must leave X fixed and operate only on Y and Z as 
, so the rotation axis dimension is pointing in the opposite direction from the Y-axis. Thus a the angle for the rotation is the negative of the angle we would see in the axes above, and since cos is an even function but sin is odd, we have the rotation matrix 
around the Z-axis to move your fixed line into the YZ-plane
around the X-axis to move that line to the Y-axis
to move your rotation line back into the YZ-plane
to move your rotation line back to the original line.
where the * terms are the terms from the 3D rotations above.
. Then

and, in general, a scaling matrix looks like
where the
are the scaling factors for x, y, and z respectively. 
for the scaling transformation.
to the X-coordinate and
to the Y-coordinate of every point in 2D space, we see that
so that the matrix
gives a 2D translation. 

.
. The values of A and B are adjusted to give precisely the view that you want, and the z-term of the result is usually dropped to give the needed 2D view of the 3D object. An example is the classical cabinet view shown below: 

is clearly the rotation around the same line by the angle
.
and the 3D case is a simple extension of this.

