University of Babylon College of Information Technology Department of Information Network Day: Wednesday Date: 21-11-2012 Stage: Second. Topic: Introduction to Computer Graphics Lecture3: Reflection and Shear Transformations. General Objective: The students will be able to do the variant two dimensional transformations on any object. Procedural Objective: 1. The students will be able to apply the reflection to reflect any object about different axis. 2. The students will be able apply the shear to make x or y shear on an object. Teaching aids: Lecture (presented by MS-power point program on the laptop), LCD monitor, discussion between lecturer and students, whiteboard, pens. 1 Other Transformations 7.1 Introduction Basic transformations such as translation, scaling, and rotation are included in most graphics packages. Some packages provide a few additional transformations that are useful in certain applications. Two such transformations are reflection and shear. 7.2 Reflection A reflection is a transformation that produces a mirror image of an object. The mirror image is generated relative to an axis of reflection. Objects can be reflected about the x axis using the following transformation matrix: (7-1) This transformation keeps x values the same, but "flips" the y values. The resulting orientation of an object after it has been reflected about the x axis is shown in Fig. (7-1). FIGURE 7-1 Reflection of an object about the x axis. 2 A reflection about the y axis flips the x coordinates while keeping y coordinates the same. We can perform this reflection with the transformation matrix: (7-2) Figure (7-2) illustrates the change in position of an object that has been reflected about the y axis. FIGURE 7-2 Reflection of an object about the y axis. Another type of reflection is one that flips both the x and y coordinates by reflecting relative to the coordinate origin. (The axis of reflection in this case is the line perpendicular to the xy plane and passing through the origin.) We write the transformation matrix for this type of reflection as: (7-3) An example of reflection about the origin is shown in Fig. 7-3. 3 FIGURE 7-3Reflection on of an object relative to the coordinate origin. The following matrix performs a reflection transformation about the line y = x (Fig. 7-4). (7-4) FIGURE 7-4 Reflection of an object with respect to the line y = x. This transformation could be obtained from a sequence of rotations and coordinate axis reflections. One possible sequence is shown in Fig. 75. Here, we first perform a clockwise rotation through a 45° angle, which rotates the line y = x onto the x axis. Next, we perform a reflection with respect to the x axis. The final step is to rotate the line y = x back to its original position with a counterclockwise rotation through 45°. Concatenating this sequence of three transformations yields the matrix 74 4. An equivalent sequence of transformations is first to reflect the object about the x axis, then rotate counterclockwise 90°. FIGURE 7-5Sequence of basic transformations to produce reflection about the line y = x: (a) Clockwise rotation of 45°; (b) reflection about the x axis; (c) Counterclockwise rotation by 45°. 5 To obtain a reflection about the line y = -x, we perform the transformation sequence: (1) clockwise rotation by 45°, (2) reflection about the y axis, and (3) counterclockwise rotation by 45°. This sequence produces the transformation matrix: (7-5) Figure (7-6) shows the original and final positions for an object reflected about the line y = - x. FIGURE 7-6 Reflection with respect to the line y = -x. 7-3 Shear These transformations produce shape distortions that represent a twisting, or shear, effect, as if an object were composed of layers that are caused to slide over each other. Two common shearing transformations are those for x-direction shear and y-direction shear. An x-direction shear is produced with the transformation matrix: (7-6) 6 Any real number can be assigned to the parameter SHx. This transformation affects only the x coordinates; y-coordinate values remain unchanged. Each point in an object is displaced horizontally by a distance that is proportional to the y coordinate. Setting SHx to 2 changes the square in Fig. 7-7 into a parallelogram. Negative values for SHx would produce horizontal shifts to the left. FIGURE 7-7 A unit square (a) converted to a parallelogram (b) using the x- direction shear matrix (7-6) with SHx = 2. A similar shearing transformation matrix can be set up to generate ydirection shearing: (7-7) This transformation generates vertical shifts in coordinate positions. Parameter Shy can be set to any real number, which alters the y component of a coordinate position by an amount that is proportional to the x value. Figure 7-8 illustrates the conversion of a square into a parallelogram with SHy = 2. 7 FIGURE 7-8A unit square (a) is turned into a parallelogram (b) using the y-direction shearing transformation matrix (7-7) with SHy = 2. 8