Previous Section  < Day Day Up >  Next Section

Visualization Experience

On the CD-ROM, you will find a demo named Transformations. Here's a brief description from the programmers:

This program was designed to help you understand the principles of 2D transformations applied to an object. Matrices are used to rotate or translate a quad around the grid. Users can use this application to get a visual representation while learning the basics of matrix concatenation.

The user can add, select, move, and trace quads on the grid as well as undo and redo actions applied to a quad. During the experience, the user can view information about the current location of each quad.

Michael Wigand and Michael Fawcett

This demo is also interactive. You can plug values into a transformation matrix and then see how the object moves as a result. You might want to try setting up a few examples by hand first and then run the demo to see if it has the effect you expected.

You can run the demo by double-clicking the Transformations.exe file. As soon as the demo is loaded, you should see a window with a red grid and a colored box in the middle. You can move this box around the screen using transformation matrices. The toolbar is labeled for you in Figure 6.11 so that you can follow the instructions listed next.

Figure 6.11. The toolbar for the Transformations demo.

graphics/06fig11.gif

To get started, click the Apply matrix button. A window pops up with a 3x3 matrix. Enter the following values:

graphics/06equ47.gif


The box should move five units to the right and eight up.

Click the Trace button on the toolbar. This leaves an imprint of the current location. Click the Add a quad button on the toolbar. This adds a new box with the bottom-left vertex at the origin.

This time, try to move the box five units to the left and three up. After you have done so, leave the box selected (outlined in white), trace its location, and apply the following matrix to it:

graphics/06equ48.gif


What happened this time? That's right—the object scaled 3 times larger with respect to the origin. This means that it moved away from the origin as it got larger. Click the Undo button to go back to the previous location. See if you can scale the box 3 times larger without moving away from the origin. Remember that this is a three-step combo:

graphics/06equ49.gif


If you multiply these three matrices in the correct order, you should get the following combo matrix:

graphics/06equ50.gif


This time you scaled 3 times larger with respect to the box's center instead of the origin. If your screen is starting to get too messy, you can click the Clear button at this point to wipe the slate clean. If not, just create a new quad for the next set of transforms.

This time, move the box nine units to the right and four units up using this matrix:

graphics/06equ51.gif


Trace that location and then rotate 90° with this matrix:

graphics/06equ52.gif


What happened? It looks like the box just translated up and to the left, but that's not entirely what happened. Look at the blue corner of the box. Press Undo and Redo a couple times. You might notice that the box did in fact rotate 90° in addition to translating. Otherwise, you can also view the coordinates of all four vertices by clicking the Quad position button on the toolbar. Write down the coordinates in the new position, press Undo, and view the coordinates of the old position. You can also verify that the box rotated that way. So what really happened is that the box rotated with respect to the origin.

Try to rotate the box with respect to the red corner instead. That way, it stays in the same place and looks like it's just tipping over. If you're not currently at the old location, click the Undo button to go back. Now you can view the quad position to find the coordinates of the red vertex. You should find that the red corner is currently at (9,4). Now you can set up a combo to rotate 90° with respect to the red vertex. You can either perform each of these steps individually or multiply them together for one combo matrix:

graphics/06equ53.gif


Did you get the outcome you expected? I suggest that you try a few combos of your own. Experiment with the demo a little bit. You might want to consider performing your own combos by hand first and then use the demo to check your work. You can write down the four original vertices and calculate where they should end up and then view the quad position to see if that's where the computer places them in the demo. Hopefully they come out to be the same!

    Previous Section  < Day Day Up >  Next Section