如何找到两个任意多边形之间的重叠区域 [英] How do I find the overlapping area between two arbitrary polygons

查看:647
本文介绍了如何找到两个任意多边形之间的重叠区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一种方法,该方法将接受两个任意的节点列表(用于主题和剪切多边形),并输出以下任意一个:

I'm trying to create a method that will take in two arbitrary lists of nodes, for a subject and a clipping polygon, and output either:


a)重叠的面积

b)生成的(裁剪的)多边形的节点列表,以便我可以计算出面积

a) the area of the overlap
b) a list of nodes for the resulting (clipped) polygon so that I can calculate the area

我发现了很多示例,这些示例使用矩形窗口(在图形中是相当标准的)裁剪任意多边形。但这并不是我所需要的。我了解这相当复杂,尤其是当您遇到孔,凸多边形等时。我可以做出的唯一简化假设是,任意多边形将不包含任何孔。

I've found lots of examples which clip an arbitrary polygon using a rectangular window (which is fairly standard in graphics) but that's not what I need. I understand that it's fairly complex, particularly when you get holes, convex polygons and the like. The only simplifying assumption which I can make is that the arbitrary polygons will not contain any holes.

我根本不是该领域的专家,所以类似Sutherland-Hodgman算法有效吗?是否有任何已经在执行此操作的库,或者我最好的选择是按照维基百科

I'm not at all an expert in this field, so would something like the Sutherland-Hodgman algorithm work? Are there any libraries out there which already do this, or is my best bet to simply implement the algorithm as described in pseudo-code on Wikipedia?

感谢您的帮助!

推荐答案

我发现使用 JavaGeom 库效果很好。它集成了GPC Java端口(不再可用)中的代码,因此允许任意多边形操作。使用SimplePolygon2D和Polygon2DUtils.intersection(),我可以获得所需的操作。

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.

这篇关于如何找到两个任意多边形之间的重叠区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆