3.1. Compound transformations revisited
Last lecture we looked briefly at how we can use matrix multiplication to produce compound transformations. We will now illustrate this further with a worked example. If we recall from the previous lecture notes, by using compound transformations we can create any transformation and express it as a single transformation matrix. We will take the example of rotation by an angle q about a given point P. This can be performed by 3 individual transformations: translation from point P to the origin (T_{P}); rotation by angle q about the origin (Rq ); finally, translation from the origin back to point P (T_{P}). We can express this as:
Rq _{P} = T_{P}.Rq .T_{P}
If we can now take our standard transformation matrices for translation and rotation we get:
In the above equation, P_{x} and P_{y} represent the x and y coordinates of our point P. The negative values in the right hand matrix are because we are translating back from the point to the origin. We will now start multiplying these matrices together to derive a single transformation matrix Rq _{P}.
Now, we multiply the result by the right hand matrix:
This gives our finished transformation matrix which we can use to rotate any 2D coordinate by any angle, around any given point  a very flexible and useful operation. This result may look complicated, but if you work through the matrix multiplication yourself you will soon get the hang of it. Matrix multiplication does tend to get very messy if we are using algebraic expressions such as those above  multiplying numeric matrices is much nicer.
Now, we test our new transformation matrix. Figure 1(a) shows a box consisting of four points, a to d. The box is positioned with its lower left point (point a) at coordinate (2, 1). The box is 2 units wide and 1 unit tall. We will rotate this box by an angle of 90° counterclockwise about the coordinate (2, 1), i.e. about point a.
Figure 1(a). Original box prior to transformation.
The first thing we can do is simplify the transformation matrix by inserting all the values we now have. We know that q = 90° , Px = 2, Py = 1, cos 90° = 0 and sin 90° = 1. Because we are using such a nice rotation angle (i.e. 90° instead of something like 31° ), our transformation matrix should be fairly simple:
We can now use this transformation matrix to transform each point of the box. Remember, we multiply each coordinate or vector by the transformation matrix to get the resultant vector:
Now, we can either substitute each coordinate into the above matrices and evaluate each using matrix multiplication. Alternatively we can multiply out the matrices above to give us some equations which we can use to work out the new coordinates. We will try the latter method. Multiplying out gives :
Because we are using a scaling factor w = 1, we can simplify these equations further :
Now we simply substitute each coordinate’s x and y values to obtain its new position. This gives :
Point 
Original coord. 
New coord. 
a 
(2, 1) 
(2, 1) 
b 
(4, 1) 
(2, 3) 
c 
(2, 2) 
(1, 1) 
d 
(4, 2) 
(1, 3) 
Figure 1(b) below shows the new position and orientation of the box. Note that point a has not moved  which is what we should expect. We have seen that we can create any transformation we desire by combining simpler transformations together, and we can represent these new transformations using a single matrix.
Figure 1(b). New position of box after transformation.
3.2. 3D Simple transformations
We have already seen how we can define in 2D the simple transformations of translation, rotation and scaling. We have also seen how these transformations can be represented as matrices using a homogenous coordinate system. We will now quickly look at the same transformations but this time using a 3D coordinate system. The principles and matrix operations are identical to the 2D system, the only difference being that we now have a 4 value position vector (x, y, z and the weighting factor w) meaning we will now need a 4*4 transformation matrix. For translation and scaling this is a simple addition, however rotation in a 3D coordinate system is more complicated.
The matrix operation for a translation of t_{x}, t_{y}, and t_{z} is given as :
A 3D scaling operation by S_{x}, S_{y} and S_{z} is expressed as:
As we have already seen, in a 2D coordinate system we can easily perform rotations about the origin (or indeed any point, by creating a compound transformation). However, we are now moving into a 3D coordinate system which provides additional freedom and complexity. We can no longer perform a rotation by simply specifying an angle, we must also specify an axis about which to rotate.
Rotating about either the x, y or z axes is the simple case and can be performed using the following transformation matrices. These matrices can be derived from the 2D rotations mentioned previously. As before, we will use the terms pitch, yaw and roll to represent rotations about the x, y and z axes respectively.
Pitching about the xaxis by an angle pitch.
Yawing about the yaxis by an angle yaw.
Rolling about the zaxis by an angle roll.
If we want to rotate about negative angles, i.e. to reverse a roll, we simply apply the transpose of each matrix.
If we want to rotate about an arbitrarily defined vector then things become a lot more complicated. We will not cover this topic in this course because there are other simpler techniques for achieving the same results which will be discussed next. However, for anyone interested, section 3.2.4 in the book Virtual Reality Systems by John Vince, contains a good description of a method to rotate about any 3D vector using quaternions.
3.3. Direction vectors and rotations
As well as being able to rotate objects about an arbitrary axis we often need to specify direction vectors. For example, in positioning the virtual observer (our viewpoint on the 3D world) we need to specify both the location of the VO, but also the direction in which the VO will be looking. There are a number of different ways in which we can specify such rotations and direction vectors, as well as some more conventions to define in their application.
We should all be familiar with unit vectors which can be specified using their 3 constituent components of x, y and z. Unit vectors have a length or magnitude of 1 and are used frequently to specify direction vectors and axes for rotation. The unit vector for the xaxis is [1, 0, 0], y is [0, 1, 0] and z is [0, 0, 1]. The unit vector (v) for the vector (d) passing through point (1, 1, 1) can be found as follows :
A unit vector has 3 axial components, x, y and z, which are equal to the cosines of the angles formed between each of these axes and the unit vector. These angles are termed direction cosines and provide an alternative method to specify a unit direction vector. Direction cosines are useful for transforming any point from one frame of reference into another. One application of this is in transforming points and objects specified in the world’s coordinate system into the coordinate system of the virtual observer (VO) which may be positioned or orientated arbitrarily with respect to the world coordinate system. This transformation can be performed using matrices as follows :
where :
Cx_{x}, Cx_{y}, and Cx_{z} are the direction cosines of the VO’s xaxis with respect to the x, y and z world coordinate axes.
Cy_{x}, Cy_{y}, and Cy_{z} are the direction cosines of the VO’s yaxis with respect to the x, y and z world coordinate axes.
Cz_{x}, Cz_{y}, and Cz_{z} are the direction cosines of the VO’s zaxis with respect to the x, y and z world coordinate axes.
As an example to show how this system works, let us imagine the VO’s coordinate system is orientated as shown by the smaller, darker set of axes in figure 2. That is, the VO’s xaxis is aligned along negative z in the world coordinates, the yaxis is aligned along negative x and the zaxis is aligned along positive y.
Figure 2. Rotated secondary coordinate system superimposed on original axes.
Transforming any point within the world coordinates into the VO’s frame of reference can be given by the following operation :
If the VO happened to be gazing on the scene from an arbitrary point away from the origin then we combine a translation into the above operation. Using this system we can translate from the world coordinate system into the VO’s coordinate system with the VO positioned or orientated freely anywhere in the 3D space.
Another technique for specifying an orientation uses separate rotations applied in sequence about the three fixed axes x, y and z. As we mentioned earlier, rotations about the x, y and z axes are termed pitch, yaw and roll, respectively. By applying pitch, yaw and roll successively we can achieve any orientation we desire. The order of application of these rotations is vitally important, if the order is changed at all then you may get very different results. Any order is permissible, but again this is a matter of convention, we must choose a sequence and stick to it in order to avoid confusion. One popular sequence is to apply the rotations in the order roll, pitch and yaw. We will also use this convention.
Looking again at figure 2, we can see that the orientation of the VO can be obtained using a roll of +90° followed by a pitch of 90° . As before, the matrix operations for these rotations can be concatenated together to form a single transformation.
If the VO is located and orientated within the world coordinates of the virtual environment (VE) then to transform objects and points from the VE’s frame of reference to that of the VO, we must use the inverse transformations. If the VO is also positioned away from the origin then we must also add a translation into the overall transformation. So, to convert objects and points into the VO’s frame of reference we can use :
The inverse transformations for roll, pitch and yaw can be found by calculating the transpose of the original roll, pitch and yaw matrices. These are shown in the following table. The left column shows the original matrices which were given earlier and the right column gives the transpose of these matrices.
Original 
Transpose 
Pitch 
Pitch 
Yaw 
Yaw 
Roll 
Roll 
The difference between fixed angles and Euler angles is very subtle. Fixed angles are taken relative to a specific static frame of reference, for example the world or VE’s coordinate system. Euler angles, however, are relative to the rotating frame of reference. Euler angles and fixed angles both perform exactly the same function, they are each just a different way of going about it  another convention.
We begin with the secondary coordinate system (the one we are going to rotate) mutually aligned to the VE’s coordinate system (Figure 3(a)). If we now apply a roll of 90° we have the situation shown in figure 3(b), the smaller axes set has been rotated about the zaxis so it’s yaxis lies along the negative xaxis of the VE and it’s xaxis lies along the positive yaxis of the VE. If we now apply a pitch of 30° we can see in figure 3(c) that the pitch is applied with respect to the VE’s fixed coordinate system. Finally if we apply a yaw of 90° we get the final position shown in figure 3(d).


Figure 3(a). Mutually aligned axes. 
Figure 3(b). After a fixedangle roll of 90° . 


Figure 3(c). After a fixedangle pitch of 30° . 
Figure 3(d). After a fixedangle yaw of 90° . 
As before, we begin with both sets of axes mutually aligned as in figure 4(a). We will apply the exact same operations as before, however, this time when we perform a rotation we do so with respect to the rotating frame of reference and not the fixed VE coordinate system. Firstly we apply a roll of 90° as shown in figure 4(b) which is the same as our first operation using fixed angles. Now, we apply the 30° pitch which is a rotation about the xaxis, but remember, now we are using the xaxis on the rotating set of axes. This pitch results in the situation shown in figure 4(c). Notice how in this case, the pitch using Euler angles corresponds to a yaw of 30° using fixed angles. Finally we apply the 90° yaw to get the result as seen in figure 4(d).


Figure 4(a). Mutually aligned axes. 
Figure 4(b). After a Eulerangle roll of 90° . 


Figure 4(c). After a Eulerangle pitch of 30° . 
Figure 4(d). After a Eulerangle yaw of 90° . 
Note how different the two results are using either convention. In each case we could achieve the same result using the opposite convention, it simply requires a reordering of the application of roll, pitch and yaw. In fact it is even simpler than that. Any orientation achieved with one method can be duplicated using the opposite method by simply reversing the sequence of rotations. So, the result shown in figure 3(d) which was derived using a fixed angle sequence of roll 90° , pitch 30° and yaw 90° can be achieved using a Euler angle sequence of yaw 90° , pitch 30° and roll 90° .
Look again at figure 2 which was shown earlier when discussing direction cosines. This orientation can also be described using either fixed angles or Euler angles. As a simple exercise and a check to make sure what we have learned so far is consistent we will compare the transformation using fixed angles with the one we derived earlier which used direction cosines.
Figure 2 (reprinted). Rotated secondary coordinate system superimposed on original axes.
Figure 2 can be obtained by a fixed angle roll 90° , pitch 90° , yaw 0° . We can now use the transformation matrices for roll, pitch and yaw given earlier. In this case we are transposing from the world coordinate system into the new coordinate system so we need to use the transposed matrices. We can now derive the following :
Expanding this with our transposed roll, pitch and yaw matrices gives :
Evaluating all the sine and cosine terms. Remember, cos(0°) = 1, cos(90°) = 0, sin (0°) = 0 and sin(90°) = 1. This gives :
Now, we multiply matrix pairs starting left to right. The first matrix on the right is an identity matrix so we can simply remove it. (i.e. the matrix equivalent of multiplying something by 1  you get the same result)
Multiplying the remaining two matrices leaves us with our transformation matrix :
As we can see by comparing the result here with the matrix derived from the direction cosines, they are both identical.
Phew!
This page is maintained by Peter Young, please send any comments to (peter.young@durham.ac.uk).
Last updated: Monday 2 February, 1998.