CGAL:线段和多边形之间的交点? [英] CGAL: Intersection between a segment and a polygon?
问题描述
我有一组多边形,我想测试它与线段之间的交点。
我检查了手册,但找不到匹配的功能。
点,线,线段,三角形,平面之间的交点确实存在。
多边形之间的交点也在那里。
我的问题是:
I have a set of polygons and I want to test intersection between it and a segment. I checked the manual but I cannot find a matching function. The intersection between points, lines, segments, triangles, planes do exist. And the intersection between polygons are also there. My question is:
- 有这样的功能吗?
- 如果没有,这是否意味着我需要将多边形分解为多个部分,并在这些部分之间进行相交? (我不愿意这样做的原因是,我认为CGAL实际上可能会使用这种方式在多边形之间进行相交。为什么没有这样的函数将线与多边形相交?)或者还有其他更好的方法吗?
推荐答案
最简单的方法是创建一个Polygon_set_2对象,该对象可能包含几个多边形。要使用此集测试外部多边形的交集,您只需应用do_intersect方法。
The easiest method is to create a Polygon_set_2 object which may contain several polygons. To test an intersection of an external polygon with this set you simply apply the do_intersect method.
例如:
typedef CGAL::Polygon_set_2<Kernel, std::vector<Kernel::Point_2>> Polygon_set_2;
Polygon_set_2 ps;
Polygon_2 poly;
Polygon_2 line; // line is a polygon defined by 2 points
ps.insert(poly);
bool intersect = ps.do_intersect(line);
有关polygon_set_2的更多信息:
More on polygon_set_2:
- http://www.cgal.org /Manual/3.2/doc_html/cgal_manual/Boolean_set_operations_2_ref/Class_General_polygon_set_2.html
- http://www.cgal.org/Manual/3.2/doc_html/cgal_manual/Boolean_set_operations_2_ref/Class_Polygon_set_2.html
- http://www.cgal.org/Manual/3.2/doc_html/cgal_manual/Boolean_set_operations_2_ref/Class_General_polygon_set_2.html
- http://www.cgal.org/Manual/3.2/doc_html/cgal_manual/Boolean_set_operations_2_ref/Class_Polygon_set_2.html
我希望清楚,
Kiril
I hope it's clear, Kiril
这篇关于CGAL:线段和多边形之间的交点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!