Java Reference
In-Depth Information
void scale(double scaleX, double scaleY)
void shear(double shearX, double shearY)
Each of these adds or concatenates the transform specified to the existing transform object for a Graph-
ics2D object. Therefore, you can cause a translation of the coordinate system followed by a rotation about
the new origin position with the following statements:
g2D.translate(5, 10); // Translate the origin
g2D.rotate(Math.PI/3); // Clockwise rotation 60 degrees
g2D.draw(line); // Draw in translate and rotated space
Of course, you can apply more than two transforms to the user coordinate system; you can apply as many as
you like. However, it is important to note that the order in which you apply the transforms matters. To see
why, look at the example shown in Figure 20-17 .
FIGURE 20-17
The figure shows just two transforms in effect, but it should be clear that the sequence in which they are
applied makes a big difference. This is because the second transform is applied relative to the new position
of the coordinate system after the first transform has been applied. If you need more convincing that the
order in which you apply transforms matters, you can apply some transforms to yourself. Stand with your
back to any wall in the room. Now apply a translation — take three steps forward. Next apply a rotation —
turn 45 degrees clockwise. Make a mental note of where you are. If you now go back and stand with your
back to the wall in the original position and first turn 45 degrees before you take the three steps forward, you
are clearly in quite a different place in the room than you were the first time around.
Next on your affine tour — how you can create completely new AffineTransform objects.
Creating AffineTransform Objects
Of course, there are constructors for AffineTransform objects: the default “identity" constructor and a
number of other constructors, but I don't have space to go into them here. The easiest way to create trans-
 
 
Search WWH ::




Custom Search