Algorithm 两个凸多边形的交集
我有两个凸多边形。多边形实现为其顶点的循环列表。如何找到这两个多边形的交点Algorithm 两个凸多边形的交集,algorithm,graphics,polygon,Algorithm,Graphics,Polygon,我有两个凸多边形。多边形实现为其顶点的循环列表。如何找到这两个多边形的交点 For each edge V1-V2 in the first polygon, Let H := Half-plane tangenting V1-V2, with the remaining vertices on the "inside". Let C := New empty polygon. For each edge V3-V4 in the second polyg
For each edge V1-V2 in the first polygon,
Let H := Half-plane tangenting V1-V2, with the remaining
vertices on the "inside".
Let C := New empty polygon.
For each edge V3-V4 in the second polygon,
Let X := The intersection between V3-V4 and H.
If V3 inside H, and V4 is outside H then,
Add V3 to C.
Add X to C.
Else if both V3 and V4 lies outside H then,
Skip.
Else if V3 outside H, and V4 is inside H then,
Add X to C.
Else
Add V3 to C.
Replace the second polygon with C.
这应该足够简单的使用;10-20个顶点,不重新计算每一帧。-O(n2)
以下是一些链接:
- (pdf)
右边缘C1
,左边缘C2
,右边缘C2
。您不需要任何复杂的渲染边,因为只有四条边。只需迭代所有可能的选项,就可以找到下一个事件点
在每个事件点,一些边出现在其交点的边界上。基本上,在每个事件点,您可以有三种情况中的一种(见图)
除了@Yola漂亮的飞机扫描描述, 中介绍了一种线性时间算法
,第7章。C&Java代码可用(在同一链接)。有几种复杂的退化情况,例如,当两个多边形在一个点相交,或者相交是一段时。在情况3中,您确定必须将V3添加到相交处吗?这似乎不正确。我重写它是为了更好地与Sutherland-Hudgman算法保持一致。