tags:

views:

320

answers:

2

I have a concave polygon stored as an Area. How would I flip/invert/mirror the polygon about the y-axis?

+2  A: 

You might try this (I'm assuming your Area object is named polygon):

polygon.transform(AffineTransform.getRotateInstance(0, 1))

The AffineTransform's getRotateInstance() static method returns a new AffineTransform object with a rotation around the vector <0, 1> (aka the Y-axis).

Peter Nix
Just a sec.... doesn't this just rotate the image anticlockwise by 90 degrees?
Il-Bhima
@Il-Bhim if you're polygon lies centered on the origin, the rotation about the y-axis will mirror the polygon, not actually move it around the coordinate system. If your polygon isn't on the origin, it will both mirror and move it.
Peter Nix
+3  A: 

You can use the Area's transform method. This takes an AffineTransform object which specifies a single affine transformation. For the case of flip you can define the following transform

AffineTransform at = new AffineTransform(new double[] {-1.0,0.0,0.0,1.0});
Il-Bhima