Using the rotate
method, you can produce an affine transform that
rotates by an angle expressed in radians. For example, if you wish to
rotate by 90°, counterclockwise, you rotate by -pi/2 radians.
Conveniently, the Math
class provides a value for pi as the
value of a class variable, Math.PI
. Thus, to create
an affine transform for a 90° counterclockwise rotation, you
write the following statements:
AffineTransform transform = new AffineTransform(); transform.rotate(- Math.PI / 2);