9.6 Graphic Transformation Matrices With these matrix classes, we can write an interactive program that shows how matrices are used in computer graphics to control the motion of graphic images in three dimensions. We can represent a three-dimensional graphic image as a set of vertices (corners) and edges (lines between the vertices). Vertices (and the edges between them) can define a flat face three vertices define a triangle, four vertices define a square, and so on. In three-dimensional space, each vertex has x, y, and z coordinates. We can assume that the z axis extends outward from and into the computer screen, with the positive direction toward the viewer. We can transform, or alter, the coordinates of a vertex in several ways. The ways our program will use are
If we represent a vertex as a row vector with an appended fourth element with value 1, then we can perform each of the preceding transformations by multiplying the vector by a 4 x 4 transformation matrix :
Since scaling is about the origin, we must first move the graphic image to the origin, apply the scaling, and then move the image back to its location. We can do the move to and from the origin with two translation operations. Similarly, to spin the image, it must be at the origin, since we want the center of rotation to be the origin. We can rotate it separately along each axis in turn . Thus, we can end up multiplying each vertex several times by the various transformation matrices in order to get the sequence of motions we want for the entire image. But there's a wonderful feature of transformation matrices we can multiply all the transformation matrices together in the order that we want to apply them and then multiply each vertex by this product matrix, called the concatenated transformation matrix. That causes the entire sequence of motions to be applied all at once to each vertex. |
Top |