Lecture 3

3D transformations

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 (TP). We can express this as:

Rq P = TP.Rq .T-P

If we can now take our standard transformation matrices for translation and rotation we get:

In the above equation, Px and Py represent the x and y co-ordinates 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 co-ordinate 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 co-ordinate (2, 1). The box is 2 units wide and 1 unit tall. We will rotate this box by an angle of 90° counter-clockwise about the co-ordinate (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 co-ordinate or vector by the transformation matrix to get the resultant vector:

Now, we can either substitute each co-ordinate 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 co-ordinates. 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 co-ordinates 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 co-ordinate system. We will now quickly look at the same transformations but this time using a 3D co-ordinate 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 co-ordinate system is more complicated.

3.2.1. Translation

The matrix operation for a translation of tx, ty, and tz is given as :

3.2.2. Scaling

A 3D scaling operation by Sx, Sy and Sz is expressed as:

3.2.3. Rotation

As we have already seen, in a 2D co-ordinate 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 co-ordinate 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.

3.2.3.1. Pitch

Pitching about the x-axis by an angle pitch.

3.2.3.2. Yaw

Yawing about the y-axis by an angle yaw.

3.2.3.3. Roll

Rolling about the z-axis 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 x-axis 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 :

3.3.1. Direction Cosines

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 worlds co-ordinate system into the co-ordinate system of the virtual observer (VO) which may be positioned or orientated arbitrarily with respect to the world co-ordinate system. This transformation can be performed using matrices as follows :

where :

Cxx, Cxy, and Cxz are the direction cosines of the VOs x-axis with respect to the x, y and z world co-ordinate axes.

Cyx, Cyy, and Cyz are the direction cosines of the VOs y-axis with respect to the x, y and z world co-ordinate axes.

Czx, Czy, and Czz are the direction cosines of the VOs z-axis with respect to the x, y and z world co-ordinate axes.

As an example to show how this system works, let us imagine the VOs co-ordinate system is orientated as shown by the smaller, darker set of axes in figure 2. That is, the VOs x-axis is aligned along negative z in the world co-ordinates, the y-axis is aligned along negative x and the z-axis is aligned along positive y.

Figure 2. Rotated secondary co-ordinate system superimposed on original axes.

Transforming any point within the world co-ordinates into the VOs 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 co-ordinate system into the VOs co-ordinate system with the VO positioned or orientated freely anywhere in the 3D space.

3.3.2. XYZ fixed angles

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 co-ordinates of the virtual environment (VE) then to transform objects and points from the VEs 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 VOs 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

3.3.3. XYZ Euler angles

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 VEs co-ordinate 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.

3.3.3.1. Fixed angles

We begin with the secondary co-ordinate system (the one we are going to rotate) mutually aligned to the VEs co-ordinate 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 z-axis so its y-axis lies along the negative x-axis of the VE and its x-axis lies along the positive y-axis 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 VEs fixed co-ordinate 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 fixed-angle roll of 90° .

Figure 3(c). After a fixed-angle pitch of 30° .

Figure 3(d). After a fixed-angle yaw of 90° .

3.3.3.2. Euler angles

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 co-ordinate 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 x-axis, but remember, now we are using the x-axis 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 Euler-angle roll of 90° .

Figure 4(c). After a Euler-angle pitch of 30° .

Figure 4(d). After a Euler-angle 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 re-ordering 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° .

3.3.4. Consistency check

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 co-ordinate 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 co-ordinate system into the new co-ordinate 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.