Transformations in Three Dimensions.

Copyright (c) Susan Laflin. August 1999.

To deal with transformations in three dimensions, you will need to use 4x4 matrices and homogeneous coordinate with 4 components, usually (x,y,z,1), but the most general form is (x,y,z,h).

Shift Transformation or Translation

The shift transformation requires the following matrix equation:


	x'		1	0	0	-Tx		x
	y'	=	0	1	0	-Ty		y
	z'		0	0	1	-Tz		z
	1		0	0	0	1		1

This corresponds to the three equations:

x' = x - Tx
y' = y - Ty
and
z' = z - Tz

While the fourth equation reduces to 1=1 , which at least confirms that you have remembered the equation correctly. This transformation corresponds to moving the point (Tx,Ty,Tz) to the origin and the reverse transformation is given by adding these values to the coordinates.

Scale Transformation

The scale transformation corresponds to the following matrix equation:


	x'		Sx	0	0	0		x
	y'	=	0	Sy	0	0		y
	z'		0	0	Sz	0		z	
	1		0	0	0	1		1

or the following three equations:

x' = Sx*x
y' = Sy*y
and
z' = Sz*z

which have the effect of multiplying each of the coordinates by the appropriate value.

Rotate Transformations

When you come to consider rotation, the situation is more complex than in the two dimensional case, because the diagram may be rotated about any of the three coordinate axes. The two-dimensional case had all diagrams in the z=0 or xy-plane and so the only possible rotation was one about the z-axis.

Rotate Transformation

The above figure shows rotation through an angle A about the z-axis. The point P=(x,y) is moved to the point P'=(x',y'), and if the length OP, (=OP'), is denoted by r, this gives

x = r cos A and y = r sin A
x' = r cos(A+B) and y' = r sin (A+B)

Using the expansions for sin(A+B) and cos(A+B) gives

	x' = r (cosA cosB - sinA sin B)	= rcosB cosA - rsinB sin A
	    = x cosA - y sinA
and	y' = r (sinA cosB + cosA sinB)	 =  x sinA + y cosA

This gives the following matrix equation for the transformation

	x'		cosA	-sinA	0	0		x
	y'	=	sinA	cosA	0	0		y
	z'		0	0	1	0		z
	1		0	0	0	1		1

which should remind you of the two-dimensional case. Note that for this and all other rotations, values along the axis about which the transformation is performed are unchanged. In the above example, z-values are unchanged.


Rotation about the x-axis has the equation

	x'		1	0	0	0		x
	y'	=	0	cosA	-sinA	0		y
	z'		0	sinA	cosA	0		z
	1		0	0	0	1		1

and rotation about the y-axis has the equation

	x'		cosA	0	sinA	0		x
	y'	=	0	1	0	0		y
	z'		-sinA	0	cosA	0		z
	1		0	0	0	1		1

and these can be expanded to give the usual three equations.

Example of Transformations

To rotate all the points through an angle A about a general line.
Step 1. Move the line to coincide with the z-axis.
Assume the line has the equation P = P1 + k D where P1 is a point 
on the line and D=(d1,d2,d3) are the direction cosines

	a) Translation T1 to move the point P1 to the origin.

	b) Rotation R1, rotate the line about the z-axis until it 
lies in the zx-plane. This requires a rotation through the angle B1 
where tan B1 = d2/d1.

	c) Rotation R2 Rotate the line about the y-axis until it 
coincides with the z-axis. If d4 = SQRT(d1*d1 + d3*d3), then this 
requires rotation through angle B2 where tan B2 = d4/d3.

So step 1 is made up of translation T1, followed by rotation R1, 
followed by rotation R2. Thus the matrix for step 1 is S1, given by	

			S1 = R2 *R1 *T1 


 Step 2. Rotate through angle A.
This is the single matrix S2 which corresponds to a rotation through 
angle A about the z-axis. 

Step 3. Return the line to its original position.
This is the inverse of S1 and requires the three steps:
	a) Rotate through angle B2 about the y-axis.
	b) Rotate through angle B1 about the z-axis. 
	c) move the origin to position P1.
so the matrix S3 is given by 	S3 = T1-1 * R1-1 * R2-1

This gives the overall transformation as  	T = S3 *  S2 *  S1