///<summary> /// Поиск пересечений Полигона и Ломаной /// </summary> public static List <Point> GetIntersection(ConvexPolygon polygon, Polyline polyline) { return(Intersect.GetIntersection(polygon, polyline.Points.ToArray())); }
// Поиск точек пересечений Полигона со списком точек (array) public static List <Point> GetIntersection(ConvexPolygon polygon, params Point[] arr) { int type = 0; // flag of ConvexPolygon type intersect (Polyline,Segment,Point) var points = new List <Point>(); var segments = Polyline.PointsToSegments(polygon.Points); var normals = polygon.Normals; switch (arr.Count()) { case 0: // Nothing return(new List <Point>()); case 1: // Point break; case 2: // Segment type = 1; break; default: // Polyline type = 2; var PolylineSegments = Polyline.PointsToSegments(arr.ToList()); foreach (var polylineSegment in PolylineSegments) { points.AddRange(Intersect.GetIntersection(polygon, polylineSegment.Begin, polylineSegment.End)); } break; } for (int index = 0; index < segments.Count; index++) { var t = segments[index]; if (type == 0) { if (!isLeft(t, normals[index], arr[0])) { return(new List <Point>()); } } else if (type == 1) { if (isLeft(t, normals[index], arr[0]) && !isLeft(t, normals[index], arr[1]) || !isLeft(t, normals[index], arr[0]) && isLeft(t, normals[index], arr[1])) { foreach (var segment in segments) { //if (Intersect.GetIntersection(new Segment(arr[0], arr[1]), segment).Count > 0) points.AddRange(Intersect.GetIntersection(new Segment(arr[0], arr[1]), segment)); var newSegment = new Segment(arr[0], arr[1]); if (GetIntersection(newSegment, segment).Count > 0) { points.AddRange(Intersect.GetIntersection(new Segment(arr[0], arr[1]), segment)); } } break; } else if (!isLeft(t, normals[index], arr[0]) && !isLeft(t, normals[index], arr[1])) { return(new List <Point>()); } } } if (type == 0) { points.Add(arr[0]); } if (type == 1) { points.AddRange(new List <Point> { arr[0], arr[1] }); } return(points); }