Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  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?
like image 952
Ivan Xiao Avatar asked Jul 01 '11 17:07

Ivan Xiao


People also ask

What are the points of intersection of the line segments in a polygon?

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.

Do polygon lines intersect?

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.

How do you intersect two polygons?

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".


1 Answers

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

like image 159
kirilsolo Avatar answered Sep 20 '22 16:09

kirilsolo