AffineTransform : Java Glossary

*0-9ABCDEFGHIJKLMNOPQRSTUVWXYZ (all)

AffineTransform
java.awt.geom.AffineTransform is a class that represents a PostScript-like coordinate transformation i.e. a 3 × 3 matrix multiplication. It lets you rotate around an anchor point, translate the axes and shear (change the x and y scaling). Using negative scale factors, you can flip (reflect around the x or y axis). The transform converts an x,y coordinate to a new x',y' coordinate.
[ x']   [  m00  m01  m02  ] [ x ]   [ m00 * x + m01 * y + m02 ]
[ y'] = [  m10  m11  m12  ] [ y ] = [ m10 * x + m11 * y + m12 ]
[ 1 ]   [   0    0    1   ] [ 1 ]   [               1         ]
Though AffineTransform is often associated with drawing, it is not tied in any way to the Graphics class. It is purely mathematical.
Tips Rotating Images
Manual Use Learning More
Drawing Links
Mouse Co-ordinates

Gotchas

Tips

Manual Use of AffineTransform

The basic idea is this. A transform maps every point x,y onto a new point, by a combination of rotation, scaling, translation and mirroring. You can manually transform a point like this:

Drawing with AffineTransform

You can also simply plug an AffineTransform into your Graphics2D object. Then you can specify simple coordinates and the drawing will appear in transformed coordinates. Note that with Graphics2D, your coordinates are doubles not ints.

Correcting Mouse Co-ordinates

The catch is, the mouse knows nothing about your transforms. You need to convert mouse screen coordinates to your user-coordinates. This is the inverse of what you normally do, namely converting convenient user coordinates to pixel display coordinates. For this, you need the inverse of your transform.

You can learn more with a Google search.

Rotating Images

Rotating Images is a tad trickier than you might expect. The code snippet below will show you how it is done.

Learning More

Oracle’s Javadoc on AffineTransform class : available:
Oracle’s Javadoc on Graphics2D class : available:

This page is posted
on the web at:

http://mindprod.com/jgloss/affinetransform.html

Optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\jgloss\affinetransform.html
Canadian Mind Products
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

IP:[65.110.21.43]
Your face IP:[54.160.244.62]
You are visitor number