Joshua Galecki
Joshua Galecki

Reputation: 327

Horizontally flip an Area in Java

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

Upvotes: 2

Views: 3075

Answers (2)

Il-Bhima
Il-Bhima

Reputation: 10880

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});

Upvotes: 3

Peter
Peter

Reputation: 8575

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).

Upvotes: 2

Related Questions