Java Reference
In-Depth Information
A fixed value, deltaX , say, is added to each x coordinate, and another value, deltaY , say, is added to
every y coordinate, and the effect of this is to move the origin of the user coordinate system relative to the
device coordinate system: Everything is shifted to the right and down compared to where it would have been
without the translation. Of course, the deltaX and deltaY values can be negative, in which case it would
shift things to the left and up. In the element classes, you move the origin of the user coordinate system so
you can to draw all elements at the same position, (0,0). This was not necessary up to now, but it turns out
to be very handy when you want to rotate elements.
A translation is one kind of affine transformation . ( Affine is a funny word. Some say its origin goes back
to Laurel and Hardy, where Ollie says, “This is affine mess you've got us into," but I don't subscribe to that
theory.) An affine transformation is actually a linear transformation that leaves straight lines still straight
and parallel lines still parallel. As well as translations, there are three other kinds of affine transformation
that you can define:
Rotation : The user coordinates system is rotated through a given angle about its origin.
Scale : The x and y coordinates are each multiplied by a scaling factor, and the multipliers for x
and y can be different. This enables you to enlarge or reduce something in size. If the scale factor
for one coordinate axis is negative, then objects are reflected in the other axis. Setting the scale
factor for x coordinates to −1, for example, makes all positive coordinates negative and vice versa,
so everything is reflected in the y axis.
Shear : This is perhaps a less familiar operation. It adds to each x coordinate a value that depends
on the y coordinate, and adds to each y coordinate a value that depends on the x coordinate. You
supply two values to specify a shear, sX and sY , say, and they change the coordinates in the fol-
lowing way:
• Each x coordinate becomes (x + sX * y)
• Each y coordinate becomes (y + sY * x)
You can visualize the effect of a shear transformation most easily if you first imagine a rect-
angle that is drawn normally. A shearing transform can squash it by tilting the sides — rather
like when you flatten a carton — but keep the top and bottom straight and parallel. Figure
20-16 illustrates the three affine transformations that I've just described.
FIGURE 20-16
 
 
Search WWH ::




Custom Search