[GEF4] Subtract a polygon from another polygon [message #1694989] |
Mon, 11 May 2015 09:04 |
|
What would I need to do in order to subtract the area of intersection between two polygons from one of the polygons?
I guess it's kind of the reverse of creating a Ring, or at least would use the same principles to construct the regions of overlap.
I'm happy to have a go at this anti-Ring doohickey, if someone can give me some pointers or suggestions. I'm not entirely clear how Ring does what it does, so I'm just trying to work out which bits to copy and which to change.
Colin Sharples
CTG Games Ltd
Wellington, New Zealand
|
|
|
Re: [GEF4] Subtract a polygon from another polygon [message #1694997 is a reply to message #1694989] |
Mon, 11 May 2015 09:33 |
|
GEF4 Geometry supports constructive area geometry (CAG) with Path objects, i.e. you can add(), subtract(), intersect(), and exclusiveOr() two Path objects. Here you are an example:
Polygon tri = new Polygon(0, 0, 100, 0, 50, 50);
Polygon box = new Polygon(0, 0, 100, 0, 100, 100, 0, 100);
// subtract intersection of both from of them them
Path boxWithoutTri = Path.subtract(box, Path.intersect(box, tri));
If you need to have the result in the form of a polygon, it should work to build the polygon from the rsulting Path, i.e. walking over the Path#getSegments().
Alternatively, and if you are interested in implementing a not-so-trivial algorithm, you can triangulate the polygons (this is what Ring is doing) and find intersections on the triangle level, which you can then refine using further triangulation (with the edges of intersecting triangles as cutting lines).
|
|
|
|
Powered by
FUDForum. Page generated in 0.02289 seconds