CGAL:多边形重叠测试

时间:2018-11-07 13:22:49

标签: c++ cgal

我正在寻找一个函数,用于测试2D中一个简单的多边形是否完全包含另一个简单的多边形。 here中提到的do_intersect即使多边形部分重叠也返回true。检查完全重叠的适当功能是什么?

3 个答案:

答案 0 :(得分:1)

您可以先使用do_intersect()函数,如果没有交集,请使用has_on_bounded_side()检查P1的任何点,然后检查它是否在P2内。然后,如果P2中不包含P1,则请参考P1对P2的一点进行相同的处理。

答案 1 :(得分:0)

一个凸多边形完全包含在另一个凸多边形中,前提是只有其所有顶点都包含在包含该多边形的内部。

要测试多边形中是否包含点,可以使用OpenCV函数pointPolygonTest()(see description here)(see example use here

答案 2 :(得分:0)

有点晚了,但为了后代,给出了答案。您需要遍历多边形的点并检查它们是否在有界侧

\\Assuming that CGAL::Polygon_2 type is used
typedef CGAL::Polygon_2<Kernel>                         Polygon_2;

bool do_overlap(Polygon_2 inner_polygon, Polygon_2 outer_polygon) {
    //Check if the innner_polygon vertices are all on the bounded side of the outer_polygon
    for (auto vertex_it = inner_polygon.vertices_begin(); vertex_it != inner_polygon.vertices_end(); ++vertex_it) {
        if (outer_polygon.bounded_side(*vertex_it) != CGAL::ON_BOUNDED_SIDE) {
            //First point found of the inner_polygon outside the outer_polygon is enough to say it is not completly inside.
            return false;
        }
    }
    //If no points outside are found the inner_polygon must be completely inside the outer_polygon.
    return true
}

使用此功能,您只需检查inner_polygon是否在external_polygon内,而不是相反,但是您会得到要点。

相关问题