creating polygons based on intersection

253 views Asked by At

Say I have two polygons, A and B.
Polygon A has points at (0,0), (0, 5), and (5, 0)
Polygon B has points at (-2, 2), (5, 5), and (5, 2)
My goal is to split this in to 3 different polygons
Polygon 1 would be Polygon A - where it intersects Polygon B
Polygon 2 would be Polygon B - where it intersects with Polygon A
Polygon 3 would be the intersection area.
For polygons 1 and 2, I could use java's geom.area.intersect method.
How would I go about creating polygon 3?

1

There are 1 answers

0
Erick G. Hagstrom On BEST ANSWER

Polygons 1, 2 and 3 are the same thing. :-)

You can get Area Gamma by using intersect().

Then you can subtract() Area Gamma from Polygon A to get Area Alpha (the part of A that's outside Gamma), and subtract() Gamma from B to get Beta (the part of B that's outside Gamma).

To convert back from Area to Polygon, collect the vertex points for each Area using getPathIterator(null), then feed them into the Polygon constructor.