How do I find the overlapping area between two arbitrary polygons

半世苍凉 提交于 2019-12-04 05:19:39

Are there any libraries out there which already do this ...

Polygon clipping is a complex task. I wouldn't recommend trying to do it yourself unless you want to spend many months on it. Wikipedia lists a number of clipping libraries (and IIRC in that list only Clipper is free for use in commercial applications): http://en.wikipedia.org/wiki/Boolean_operations_on_polygons#External_links

ps: I admit to a personal bias for Clipper since I'm the author :) More info here: http://angusj.com/delphi/clipper.php

Sounds like Weiler-Atherton is the one you need:

The algorithm requires polygons to be clockwise and not reentrant (self intersecting). The algorithm can support holes (as counter-clockwise polygons wholly inside their parent polygon), but requires additional algorithms to decide which polygons are holes.

Your polygons fit those criteria, right? I don't know about implementations, but it sounds like you would be better off implementing W-A than S-H if either of your polygons could be concave.

Try gpc.

I found that using the JavaGeom library worked very well. It integrates the code from the Java port of GPC (which is no longer available) and thus allows arbitrary polygon operations. Using SimplePolygon2D and Polygon2DUtils.intersection() I was able to get the desired operation.

I've tried a lot of different libraries and the one that worked best was the JTS Topological Suite which is pure Java and LGPL2 licensed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!