Cut lines with CGAL

What I'm trying to achieve is to get the intersection between a line and a lot of polygons with holes β†’ pin lines on the mask (a lot of polygons) β†’ the result will be another line. Question in CGAL: Intersection between a segment and a polygon? suggests using Polygon with two dots to represent a string. Using CGAL samples, I came up with the following snippet. My intention was to calculate the part of the line that lies inside the rectangle using the intersection. However, the result has 4 points, and apparently it computes the intersection between the polygon and the half-plane defined by the line.

Can someone shed some light on this, please?

typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel; typedef Kernel::Point_2 Point_2; typedef CGAL::Polygon_2<Kernel> Polygon_2; typedef CGAL::Polygon_with_holes_2<Kernel> Polygon_with_holes_2; typedef std::list<Polygon_with_holes_2> Pwh_list_2; int main() { Polygon_2 P; // rectangle P.push_back (Point_2 (10, 10)); P.push_back (Point_2 (20, 10)); P.push_back (Point_2 (20, 20)); P.push_back (Point_2 (10, 20)); Polygon_2 Q; // line Q.push_back (Point_2 (0, 15)); Q.push_back (Point_2 (25, 15)); Pwh_list_2 symmR; Pwh_list_2::const_iterator it; CGAL::intersection (Q, P, std::back_inserter(symmR)); for (it = symmR.begin(); it != symmR.end(); ++it) { std::cout << "--> "; print_polygon_with_holes( *it); } getchar(); return 0; } 
+4
source share

Source: https://habr.com/ru/post/1441760/


All Articles