Question

If I have a segment between 2 vertices of a polygon, is there a way to extend this segment until it reaches the polygon boundary, using CGAL? (this can happen if at least one of the vertices is a reflex vertex).

Was it helpful?

Solution

You could get the supporting line of the segment via mySegment.supporting_line() and check where this line intersects with the polygon boundary. You can then create a new Segment that is based on the found intersection points.

Let p1 and p2 be the Vertices of your Segment. If I get you right, you'd want to sort the intersection points by their coordinates and create a Segment that goes from the 1st intersection Point smaller than p1 and p2 to the 1st intersection point greater than p1 and p2. (Note that several special cases are to be handled here.)

To get the intersection points, you can iterate over the segments of your polygon and intersect each one with the mentioned supporting line via CGAL::intersection.

A more sophisticated approach would be to create an Arrangement containing your polygon, attaching an Observer to it and then adding the mentioned supporting line to the Arrangement. You'd then get the information you need from the automatic calls to obs.before_split_face() and obs.before_split_face().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top