|
||
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 one-half 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 w-space point p to a c-space point q:
To transform a c-space point back to w-space, 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 w-space to c-space matrix tm . Then, tm_inverse is used to get the c-space to w-space matrix tm_inv . The final statement transforms the c-space point p1 to the w-space 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 y-axis of c-space. 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 w-space to c-space transformation matrix to transform a point from w-space to c-space. For a point p in w-space, the following produces the corresponding point q in c-space:
This is exactly equivalent to:
There is also an inverse function c_to_w that transforms a c-space point to w-space. The following function makes use of w_to_c and c_to_w to move the cursor on the xy-plane of c-space:
|
|
|||||||||||||||
TM_TO_2D The function tm_to_2d will produce a transformation matrix that maps three non-collinear points to the xy-plane. 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 x-axis, and p3 to a point on xy-plane with a positive y-coordinate. 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. |
|