一个简单的算法多边形相交多边形、算法、简单

2023-09-08 09:04:20 作者:曾经我也肆无忌惮的笑过

我在寻找一个非常简单的算法计算多边形相交/裁剪。 也就是说,给定多边形 P 问:,我希望能够找到多边形 T 载于 P 问:,我希望 T 是所有可能的多边形中最大的。

I'm looking for a very simple algorithm for computing the polygon intersection/clipping. That is, given polygons P, Q, I wish to find polygon T which is contained in P and in Q, and I wish T to be maximal among all possible polygons.

我不介意的运行时间(我有几个非常小的多边形),我也能买得起得到多边形路口的近似值(即少点的多边形,但仍包含在多边形路口)。

I don't mind the run time (I have a few very small polygons), I can also afford getting an approximation of the polygons' intersection (that is, a polygon with less points, but which is still contained in the polygons' intersection).

但它是真的对我很重要,该算法将是简单的(便宜的测试)和preferably短(少于code)。

But it is really important for me that the algorithm will be simple (cheaper testing) and preferably short (less code).

编辑:请注意,我希望得到一个多边形重新present的交集。我并不只需要一个布尔回答的两个多边形是否相交的问题。

edit: please note, I wish to obtain a polygon which represent the intersection. I don't need only a boolean answer to the question of whether the two polygons intersect.

推荐答案

我明白楼主一直在寻找一个简单的解决方案,但不幸的是,真的有没有简单的解决方案。

I understand the original poster was looking for a simple solution, but unfortunately there really is no simple solution.

不过,我最近创建了一个开放源代码的免费软件剪辑库(Delphi编写的,C ++和C#)的剪辑各种多边形(包括自相交的)。这个库是pretty的简单易用:http://sourceforge.net/projects/polyclipping/

Nevertheless, I've recently created an open-source freeware clipping library (written in Delp C++ and C#) which clips all kinds of polygons (including self-intersecting ones). This library is pretty simple to use: http://sourceforge.net/projects/polyclipping/ .