Home > Articles

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

Running the Graphics2D Application

When you run the Graphics2D application, you see the window shown in Figure 3.29. Notice the polygon drawn in the window's lower-left corner. This is the shape that you'll transform using the commands in the Transform menu. To perform a transformation, you first choose the type of transformation from the Transform menu. After entering the appropriate values into the dialog box that appears, right-click the program's window to apply the transformation you created to the shape.

Figure 3.29Figure 3.29 The Graphics2D application at startup.

For example, choose the Translate command from the Transform menu. You see the dialog box shown in Figure 3.30. Enter the values 100 and 50 into the dialog box's edit controls and then click OK. You've just set up a transformation that will translate the polygon in the window 100 units on the X axis and 50 units on the Y axis. To apply the transformation to the shape, right-click inside the window. You then see a window like that shown in Figure 3.31, with the polygon moved up and to the right.

Figure 3.30Figure 3.30 The Transform dialog box.

Figure 3.31Figure 3.31 The translated polygon.

If you want, you can compose several transformations and apply them to the shape all at once. As an example, now select the Rotate command from the Transform menu, and enter 20 into the Transform dialog box's first edit field (the second edit field isn't used for rotations, nor are you really rotating around the X axis). After clicking OK, select the Transform menu's Scale command. Enter the values 0.5 and 1 in the dialog box's edit fields. When you click OK, the program composes both transformations—the rotation and the scaling—into the single transformation matrix. Right-click in the window to apply the transformations to the shape. You see the window shown in Figure 3.32.

Figure 3.32Figure 3.32 The rotated and scaled polygon.

A Small Matter of Infinity

As you mess around with the various transformations you can perform with the Graphics2D application, soon you'll run into trouble. Although the application's window on the screen has a finite size, the Cartesian coordinate system in which your 3D object appears is infinite in all directions.

In the case of Graphics2D, the application's window shows only a small portion of the upper-right quadrant of the Cartesian plane. As I discovered as I tested the program, it's not only possible, but downright easy, accidentally to rotate the shape out of this quadrant so that the shape no longer appears in the window. Similarly, you can translate the shape to a set of coordinates that don't appear in the window.

If the shape disappears, try performing a translation on the object to bring it back into view. Of course, unless you have some idea of where the object is located in the Cartesian plane, you may end up translating the shape even farther away from your viewing area. Bringing the shape back into the window is an exercise in frustration, so watch what you're doing.

Take some time now to experiment with the various types of transformations until you're sure you understand how they work. Keep in mind that each new transformation you enter acts on the shape's current vertices—that is, if you should rotate the shape 20 degrees twice in a row, the shape will end up rotated 40 degrees. To start from scratch with the polygon back in the lower-left corner of the window, restart the program.

  • + Share This
  • 🔖 Save To Your Account