Lecture 2
Co-ordinate systems and transformations
2.1. Co-ordinate systems
In order to create a three dimensional (3D) environment we need to be able to position points, facets and objects within a common frame of reference. We need to be able to refer to points within 3-space simply and consistently. Although there are several different ways which can be used to specify points in a 3D environment, Cartesian co-ordinates are the most familiar and most commonly used within computer graphics applications.
3D Cartesian co-ordinates use 3 perpendicular axes, x, y, and z as shown in figure 4. Most people will be familiar with the two dimensional x and y co-ordinates where x is the horizontal axis and y is the vertical axis. Three dimensional x, y and z co-ordinates are simply an extension of this system with the additional z axis perpendicular to both the x and y axes. You can imagine the x and y axes drawn on a sheet of paper, the z axis goes into or comes out of the paper.
Figure 1. The 2 dimensional x-y plane.
Figure 2. The 2 dimensional x-z plane, with the viewpoint slightly offset to make both axes apparent.
Figure 3. The x-z plane (left) and x-y plane (right).
Figure 4. The complete three dimensional, x-y-z, co-ordinate system.
The fact that the x, y and z axes all point in the particular directions as shown in figures 1 to 4 is simply a matter of convention. There are a number of different conventions used in various 3D engines, ray tracing programs, virtual reality systems, etc. The co-ordinate system we will be using throughout this course is termed a right-handed system, as illustrated in figure 4.
2.1.1. Co-ordinate conventions
Various 3D engines and VR systems use different co-ordinate conventions which often leads to much confusion when working between such systems. There are three main differences which should be taken into consideration, the orientation of the co-ordinate system, the sign of the axes, and the sign of rotation angles about the various axes.
2.1.1.1. Orientation of the axes
The first thing we need to consider is which direction each of the axes actually represents. By convention the x axis almost always lies horizontally from left to right. The difference between some systems comes in the orientation of the y and z axes.
The convention we will be using (generally more widely used) has y as the vertical axis. This leaves z to extend into and out of the screen as it were. Some systems however use z as the vertical axis, with the y axis extending into and out of the screen.
2.1.1.2. Right-handed or left-handed co-ordinate systems
To determine the sign of the axes we need to know which portion of each axis (with respect to the origin) is positive and which is negative. The co-ordinate system which we will be using (figure 4) is termed a right-handed system. By extending the thumb, first and middle fingers on your right hand and aligning them as if they were the x, y and z axes, respectively, then the sign and orientation of each axis can be determined. Each finger points in the positive direction of the axis. A left-handed system would work equally well, it is simply a matter of convention.
2.1.1.3. Right-handed or left-handed rotations
Finally, we need to consider the sign of rotations around any of the axes. Another hand convention is used to distinguish between the two systems. Close all four fingers as if grasping one of the axes within your hand and extend your thumb to point parallel to the positive direction of the axis. Imagine the curl of your fingers towards the finger tips as the positive direction of rotation about that axis.
Again, we will be using a right handed system throughout this course.
Rotations about the x, y and z axes are each termed differently as pitch, yaw and roll respectively. This assignment is dependent on the co-ordinate system and conventions used, but in our system a pitch is a rotation about the x-axis, yaw is rotation about the y axis and roll is rotation about the z axis. These are shown in figure 5.
Figure 5. Roll, pitch and yaw illustrated on their respective axes.
Matrices are used frequently within 3D graphics for performing transformations and operations upon sets of co-ordinates. The most common operation which we need to perform is matrix multiplication, a brief reminder of which is given here.
Matrix multiplication is referred to as the multiplication of rows into columns. In order to multiply two matrices, A and B, the number of columns in A must equal the number of rows in B. For example, in figure 6, A has n columns and B has n rows so multiplication is possible and will result in a matrix with same number of rows as A (m) and the same number of columns as B (p).
Figure 6. Matrix multiplication : rows into columns
Figure 7(a) shows an algebraic example of the actual multiplication process. Figure 7(b) shows a numeric example on larger matrices.
One thing to note about matrix multiplication is that it is not commutative. In the above example (figure 6), A*B is not necessarily equal to B*A.
(a)
(b)
Figure 7(a) and 7(b). Examples of matrix multiplication
Simple transformations such as translation, rotation and scaling of objects and vectors can be performed using matrices. Firstly we look at these 3 transformations as applied to a 2D co-ordinate system.
Translation simply moves an objects position by given offset. This is performed by adding the translation vector to the all co-ordinates within the object. For example, in figure 8(a) the box is positioned with its bottom left corner at point (1.5, 0.5). The size of the box is 2 units wide and 1 unit tall. If we translate this box by the vector (-0.5, 2.0) which is illustrated by the blue arrow, we see in figure 8(b) that the box moves to its new position of (1.0, 2.5) which is obtained by simply adding the translation vector to each set of co-ordinates. Note that the box’s size and orientation remain unchanged.
Expressing this mathematically, we want to find the new co-ordinates (x¢ , y¢ ) from the original co-ordinates (x, y) by applying the translation (t_{x}, t_{y}). This is simply :
Figure 8(a). Original position of box. |
Figure 8(b). Box after translation of (-0.5, 2.0). |
Scaling adjusts the positions of all the points in an object by the same factor and as a result it alters both the size and position of an object. If we look at the same box as before, shown again in figure 9(a). This time we apply a scaling transformation of (0.5, 3.0). All the co-ordinates of the box have their x-values scaled by a factor of 0.5 and their y-values scaled by a factor 3.0. This results in the final position and size shown in Figure 9(b). Note that the orientation of the box has not changed, it has been made narrower and taller.
Again, expressing this mathematically to obtain the new co-ordinates (x¢ , y¢ ) from the original co-ordinates (x, y) by applying the scaling factor (S_{x}, S_{y}).
To make this even more convenient we can express the transformation as a matrix multiplication as follows. Looking at the equation below and it’s three matrices, the vector (right) is multiplied by the transformation matrix (centre) to produce the resultant vector (left).
Note that in the examples above we are scaling using the origin (0, 0) as the centre of the scaling.
Figure 9(a). Original position of box. |
Figure 9(b). Box after scaling by (0.5, 3.0). |
Rotation changes the position and orientation of shapes by rotating each of the points in the shape around a common point, or centre of rotation. For simplicity we will use the origin as the centre of rotation. Figure 10(a) shows the original box from the previous two examples. Figure 10(b) shows the result of a rotation of 45° counter clockwise about the origin. Note that the actual shape or size of the box has not changed, only it’s position and orientation.
The new positions of each of the points after a rotation through an angle q about the origin can be found using :
Note that the new positions for x¢ and y¢ now depend on both the values for the previous x and y. As with scaling transformations, a rotation operation can be expressed using matrices.
Figure 10(a). Original position of box. |
Figure 10(b). Box after rotation 45° counter clockwise |
The previous section showed how we could mathematically represent the transformations of translation, scaling and rotation. Both scaling and rotation can be represented very conveniently using matrices, but unfortunately translation cannot. It would be nice to be able to perform all transformations using the same operation, i.e. by multiplying a position vector by a transformation matrix. This is where homogeneous co-ordinates come in useful.
Homogeneous co-ordinates add an extra scaling co-ordinate (typically w) to a normal 2D or 3D vector. In order to convert between homogeneous co-ordinates and normal co-ordinates we must take this scaling factor into consideration.
Normal 2D vector
Homogeneous 2D vector
Homogeneous 3D vector
In homogeneous co-ordinates, 2 points andare only equal if and.
To convert a normal vector into homogeneous co-ordinates, simply add the additional "w" co-ordinate with a value of 1. To convert a vector using homogeneous co-ordinates into a normal vector, divide each of the values by the scaling factor w.
A single point in normal co-ordinate space can be represented by many points in homogeneous co-ordinates. For example :
Finally, if the scaling factor, w, is zero then the point is at infinity.
If we now return to our transformations and see how we can represent them using homogeneous co-ordinates and matrix operations.
Taking the problem of translation again, now that we are using homogeneous co-ordinates to represent the vectors it is possible to use matrices to perform the transformation. The transformation matrix has to be 3*3 in size now, due to the homogeneous co-ordinates being represented as 3 value vectors. The 2D translation values are given again as t_{x} and t_{y}.
The scaling and rotation transformations could already be performed using matrix multiplication, however we need to adjust the transformation matrix to account for the homogeneous co-ordinates. As before, the scaling values are given by S_{x} and S_{y.}
The rotation transformation is performed using matrices and homogeneous co-ordinates as follows. As before, the rotation angle is represented by q and the centre of rotation is the origin.
2.4.4. Compound transformations
We have just seen how we can use various transformation matrices to apply rotations, translations and scaling operations. Each of these transformations is represented as a 3*3 matrix (or 4*4 in the case of 3D co-ordinates). We can combine any set of transformations by simply multiplying the individual matrices together.
Any transformation may be expressed as a matrix. For example, if we wanted to perform a scaling operation (S) followed by a translation (T) we simply multiply the two transformation matrices together to give a 3*3 compound matrix which will perform both operations. This is shown below.
As we mentioned before, matrix multiplication is not commutative and the order of application of the transformations is vitally important. A different order will produce very different results. The only exception to this rule is that the order is not important if the transformations are of the same type. I.e. a translation followed by a translation, a rotation followed by a rotation, etc.
An example of one such use of compound transformations is to provide more generic transformations, e.g. rotation about an arbitrary point. A common method for achieving this is to compound a number of standard transformations to achieve the same result. For example, if we wanted to rotate an object about a point P (we will denote this operation as R_{P}) we would perform the following series of transformations all of which can be concatenated into a single transformation matrix. Firstly we must translate the object from point P to the origin with the translation T_{-P}. We then rotate the object about the origin (R_{O}) using the standard rotation transformation. Finally, we translate the object back to the point P using the translation T_{P}. So, we can create a transformation R_{P} which can rotate about any point P as follows : R_{P} = T_{-P}R_{O}T_{P}.
This page is maintained by Peter Young, please send any comments to (peter.young@durham.ac.uk).
Last updated: Monday 26 January, 1998.