【问题标题】:Intersection of two convex polygons两个凸多边形的交集
【发布时间】:2012-10-17 13:36:17
【问题描述】:

我有两个凸多边形。多边形被实现为其顶点的循环列表。如何找到这两个多边形的交集?

【问题讨论】:

    标签: algorithm graphics polygon


    【解决方案1】:

    您可以从两个多边形都是凸的这一事实中受益。有了这些知识,您可以使用以下扫描线算法实现 O(n) 时间:

    找到两个多边形中的最高点。为简单起见,假设您没有水平边缘。创建构成多边形左右边界的边列表。

    在扫过平面时,您会存储 4 条边。 left_edge_C1right_edge_C1left_edge_C2right_edge_C2。您不需要任何复杂的边缘来绘制边缘,因为它们只有四个。您可以通过迭代所有可能的选项来找到下一个事件点。

    在每个事件点,一些边缘出现在它们的交点的边界上。基本上,在每个事件点,您都可以选择三种情况之一(见图)。

    【讨论】:

      【解决方案2】:

      除了@Yola 漂亮的飞机扫描描述, 有一个线性时间算法描述 Computational Geometry in C,第 7 章。C 和 Java 代码可用(在同一链接)。有几种棘手的退化情况,例如,当两个多边形在一点相交时,或者相交是一个线段。

      【讨论】:

        【解决方案3】:
        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)


        这里有几个链接:

        【讨论】:

        • 你确定我必须在案例 3 的交叉点添加 V3 吗?似乎不正确。
        • 我重写了它以更好地与 Sutherland-Hudgman 算法保持一致。
        猜你喜欢
        • 2017-07-05
        • 1970-01-01
        • 2010-10-19
        • 2017-03-17
        • 2015-08-17
        • 2011-07-03
        • 1970-01-01
        • 2015-02-25
        • 2020-03-20
        相关资源
        最近更新 更多