

Transformation Matrices



Introduction In SilverScreen, a transformation matrix is a 4x4 array of doubles. One can view a transformation matrix as a function that maps points from one space to another space, typically representing some combination of the scaling, rotation and translation operations. For a point (x1,y1,z1), and a transformation matrix T, the mapping to (x2,y2,z2) is defined by the matrix multiplication [x2 y2 z2 1] = T . [x1 y1 z1 1]
Transformation matrices may be multiplied together to produce composite transformations. For example, if the matrix T maps (x1,y1,z1) to (x2,y2,z2), and if the matrix S maps (x2,y2,z2) to (x3,y3,z3), then the matrix product T . S will map (x1,y1,z1) to (x3,y3,z3).
Most commonly, matrices are multiplied to produce composite transformations. The chain of multiplications begins with the unity matrix, a matrix that has the value one in each diagonal element, and the value zero in all other elements. This matrix, if used to transform the point (x1,y1,z1), will map the point onto itself. Thus the unity matrix is, in effect, a null transformation. 


Example A typical operation performed with matrices is the following:
A polygon with points p1, p2, p3 is to be scaled to onehalf its size by scaling about the point p1. Here we assume p1 = (x1,y1,z1), p2 = (x2,y2,z2), and p3 = (x3,y3,z3).
The result of these operations is a composite transformation matrix that will scale all points in the polygon about the point p1.



Translation, Rotation, Scaling There are three types of transformation matrices that are explicitly supported by SilverScreen API functions: translation, rotation, and scaling. Each of these functions performs two operations: First, a transformation matrix is created; second, the transformation matrix is multiplied into a composite matrix. The functions that perform these operations are:
The scaling and rotation functions are designed so that rotation and scaling can be performed independently on each axis.
Here is the C code that will produce the composite transformation matrix described in steps 1 through 7 above.



TM_CSPACE, TM_INVERSE, TM_TRANSFORM In addition to the simple transformation functions described above, the SilverScreen API contains a number of specialized transformation tools.
The function tm_cspace will produce a transformation matrix that maps points from world space to the current construction space. The following will transform a wspace point p to a cspace point q:
To transform a cspace point back to wspace, the function tm_inverse is used. The inverse function produces a matrix which maps in the opposite direction of the original matrix. The following will first get the wspace to cspace matrix tm . Then, tm_inverse is used to get the cspace to wspace matrix tm_inv . The final statement transforms the cspace point p1 to the wspace point p2.
For a more concrete example, consider the following problem. For a point p , we wish to locate a point q that is 2 units from p in the direction of the positive yaxis of cspace. Although this description may sound complicated, this operation is, in fact, fairly common in geometric programming. The solution is:



W_TO_C and C_TO_W The function w_to_c implicitly uses the wspace to cspace transformation matrix to transform a point from wspace to cspace. For a point p in wspace, the following produces the corresponding point q in cspace:
This is exactly equivalent to:
There is also an inverse function c_to_w that transforms a cspace point to wspace. The following function makes use of w_to_c and c_to_w to move the cursor on the xyplane of cspace:



TM_TO_2D The function tm_to_2d will produce a transformation matrix that maps three noncollinear points to the xyplane. For the points p1 , p2 , and p3 , the tm_to_2d transformation will map p1 to the origin, p2 to a point on the positive xaxis, and p3 to a point on xyplane with a positive ycoordinate. This function provides a powerful tool for solving 3D problems in 2D.
Suppose, for example, that the points p1 , p2 , and p3 form a triangle somewhere in 3D space. To compute the area of this triangle, we can do the following:



For an excellent treatment of the use of transformation matrices, see the Foley, van Dam, Feiner, and Hughes book. 
