|
| ||||
6. AffineTransformInstances of the class java.awt.geom.AffineTransform represent the transformation from one coordinate system to another. AffineTransform was used to save and restore the transform state of a Graphics2D in a previous example. AffineTransform can also be useful when you need to compute and store transformed coordinates before you draw. There are several ways to create and build up AffineTransform instances. The simplest is to build them up the same way one can in Graphics2D:
Each of these methods operates just like the equivalent version in Graphics2D. Each interprets its arguments in the current transformed coordinates, then transforms the system appropriately. Using these methods a single AffineTransform instance can be built up to represent a whole sequence of transformations. If all you need is an AffineTransform to represent one of these transformations, it can be created in one step:
Each of these creates an AffineTransform representing the appropriate transformation. Two instances of AffineTransform can be combined with the
The concatenate method combines two AffineTransform instances into one. The
resulting transform is the coordinate system transform of the first transform, followed by
the transform of the second. The first transform instance is modified to be this
resulting transform (much the way the transformation methods modify the instance).
Which of these two methods you use is largely a matter of preference and situation.
If you are being passed AffineTransform objects then you need to manipulate them with There is also a method Once you have an instance of AffineTransform, you can use it several ways. AffineTransform has methods for transforming distances, points, and entire shapes. It can also compute inverse transforms is needed (useful for mapping mouse events). Graphics2D, as we saw earlier, has methods for getting and setting the transform. It also has a method for transforming by an instance of AffineTransform. In the next sections, we'll see examples of these operations. |
|
|
| |||||||