///<summary> /// Проверка самопересечения ломаной /// </summary> public static bool CheckSelfIntersection(List <Segment> segments) { int start_j = 1; for (int i = 0; i < segments.Count - 1; i++) { for (int j = start_j; j < segments.Count; j++) { if (i != j && i != j - 1 && j != i - 1) { if (Intersect.IsLinePartsIntersected(segments[i].Begin, segments[i].End, segments[j].Begin, segments[j].End)) // if (Intersect.IsIntersected(segments[i], segments[j])) { return(true); } } } start_j++; } return(false); }
///<summary> /// Проверка самопересечения многоугольника /// </summary> public static bool CheckSelfIntersection(List <Segment> segments) { int start_j = 1; // нет проверки пересечения для отрезка last-0 for (int i = 0; i < segments.Count - 1; i++) { for (int j = start_j; j < segments.Count; j++) { if (i != j && i != j - 1 && j != i - 1 && !(i == 0 && j == segments.Count - 1)) { if (Intersect.IsLinePartsIntersected(segments[i].Begin, segments[i].End, segments[j].Begin, segments[j].End)) // if (Intersect.IsIntersected(segments[i], segments[j])) { return(true); } } } start_j++; } return(false); }
///<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); }