CGAL: Intersection between a segment and a polygon?

独自空忆成欢 提交于 2019-12-10 13:27:59

问题


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:

  1. Is there such a function?
  2. If not, does it mean I need to break down the polygons into segments and do intersection among these segments? (The reason that I am reluctant to do this is, I thought CGAL might in fact use this way to do intersections between polygons. How come there is no such a function for intersecting a line and a polygon?) Or is there any other better way to do it?

回答1:


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.

For example:

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);

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

I hope it's clear, Kiril



来源:https://stackoverflow.com/questions/6551254/cgal-intersection-between-a-segment-and-a-polygon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!