-
Notifications
You must be signed in to change notification settings - Fork 43
Sweep Line 2D
Justin edited this page Mar 14, 2022
·
3 revisions
CGAL provides a sweep line algorithm for the intersection of curves. The sweep line can check if a intersect exists, get all the intersection points and find the unique sub curves from a intersections.
Note - For intersection operations it is recommended to use the EEK kernel. Precision maybe a issue if the EIK kernel is used.
This is provided through the SweepLine class of which a static instance can be used as follows.
//Create some segments
var segments = new Segment2d[]
{
new Segment2d(new Point2d(1,5), new Point2d(8,5)),
new Segment2d(new Point2d(1,1), new Point2d(8,8)),
new Segment2d(new Point2d(3,1), new Point2d(3,8)),
new Segment2d(new Point2d(8,5), new Point2d(8,8))
};
//Get a instance to the sweep line
var instance = SweepLine<EEK>.Instance;
var doIntects = instance.DoIntersect(segments, segments.Length);
//Find all the unique segments
var subCurves = instance.ComputeSubcurves(segments, segments.Length);
//Find all the intection points
var points = instance.ComputeIntersectionPoints(segments, segments.Length);
Below is a image of the intersecting segments.