两个凸多边形相交 [英] Intersection of two convex polygons

查看:304
本文介绍了两个凸多边形相交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

 对于第一个多边形的每个边V1,V2,
    令H:=半平面tangenting V1-V2时,与剩余的
        在内部的顶点。
    令C:=新空的多边形。
    为在第2多边形的每个边V3-V4,
        令X:= V3,V4和H之间的交集
        如果V3的内部H和V 4是H以外的话,
            添加V3为C.
            增加X C.
        否则,如果两个V3和V4在于ħ外然后,
            跳跃。
        否则,如果V3ħ外,和V4是里面H,则,
            增加X C.
        其他
            添加V3为C.
    更换第二个多边形C.
 

这应该足够简单的使用; :10-20顶点和不重新计算每一帧。 — O( N 2


下面是几个链接:

I have two convex polygons. Polygons are implemented as cyclic lists of their vertices. How to find an intersection of this two polygons?

解决方案

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.

This should suffice for simple usage; 10-20 vertices and not recalculating every frame. — O(n2)


Here is a few links:

这篇关于两个凸多边形相交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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