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:
A polygon is any closed, 2-dimensional figure that is made entirely of line segments that intersect at their endpoints. Polygons can have any number of sides and angles, but the sides can never be curved. The segments are called the sides of the polygons, and the points where the segments intersect are called vertices.
Polygons can intersect in three ways: Overlap—Area of overlap can be produced by leaving the Output Type to its default value (LOWEST). Common boundary/touch at a line—This type of intersection can be produced by specifying LINE as the Output Type.
Compute the center of mass for each polygon. Compute the min or max or average distance from each point of the polygon to the center of mass. If C1C2 (where C1/2 is the center of the first/second polygon) >= D1 + D2 (where D1/2 is the distance you computed for first/second polygon) then the two polygons "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.
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:
I hope it's clear, Kiril
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With