Java Reference
In-Depth Information
Figure 20-16 shows the following:
• A rotation of −<Symbol>π</Symbol>/4 radians, which is the same as a rotation of −45 degrees.
Rotation angles are expressed in radians, and a positive angle rotates everything from the positive
x -axis toward the positive y -axis — therefore clockwise. The rotation in Figure 20-16 is negative
and therefore counterclockwise.
• A scaling transformation corresponding to an x scale of 2.5 and a y scale of 1.5.
• A shearing operation where only the x coordinates have a shear factor. The factor for the y co-
ordinates is 0 so they are unaffected, and the transformed shape is the same height as the original.
The AffineTransform Class
The AffineTransform class in the java.awt.geom package represents an affine transformation. Every
Graphics2D object contains an AffineTransform object. The default AffineTransform object in a graph-
ics context is the identity transform , which leaves user coordinates unchanged. The transform is applied to
the user coordinate system anyway for everything you draw, but all the coordinates for an entity that is dis-
played are unaltered by default. You can retrieve a copy of the current transform object for a graphics con-
text object by calling its getTransform() method. For example:
AffineTransform at = g2D.getTransform(); // Get current transform
Although this retrieves a copy of the current transform for a graphics context, you can also replace it by
another transform object:
g2D.setTransform(at);
You can retrieve the transform currently in effect with getTransform() , set it to some other operation
before you draw some shapes, and then restore the original transform later with setTransform() when
you're finished. The fact that getTransform() returns a reference to a copy, rather than a reference to the
Search WWH ::




Custom Search