Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » [GEF4] Subtract a polygon from another polygon
[GEF4] Subtract a polygon from another polygon [message #1694989] Mon, 11 May 2015 09:04 Go to next message
Colin Sharples is currently offline Colin SharplesFriend
Messages: 96
Registered: July 2009
Location: Wellington, New Zealand
Member

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 Go to previous messageGo to next message
Matthias Wienand is currently offline Matthias WienandFriend
Messages: 230
Registered: March 2015
Senior Member
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).
Re: [GEF4] Subtract a polygon from another polygon [message #1695097 is a reply to message #1694997] Tue, 12 May 2015 04:43 Go to previous message
Colin Sharples is currently offline Colin SharplesFriend
Messages: 96
Registered: July 2009
Location: Wellington, New Zealand
Member

Oh cool, I didn't realise that was in Path, that is exactly what I am looking for.

Colin Sharples
CTG Games Ltd
Wellington, New Zealand
Previous Topic:[Zest] Create a Nested-Node Link Graph
Next Topic:runtests script missing in GEF Build R-3.4.2-200902171642 automated test
Goto Forum:
  


Current Time: Tue Mar 19 06:37:38 GMT 2024

Powered by FUDForum. Page generated in 0.02289 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top