public bool intersects(LineD l) // проверяет, пересекаются ли два отрезка, концы не считаются { int o1 = orientation(l.a); int o2 = orientation(l.b); int o3 = l.orientation(a); int o4 = l.orientation(b); //if (o1 == 0 && includes(l.a)) return true; //if (o2 == 0 && includes(l.b)) return true; //if (o3 == 0 && l.includes(a)) return true; //if (o4 == 0 && l.includes(b)) return true; if (o1 == 0 || o2 == 0 || o3 == 0 || o4 == 0) { return(false); } if (o1 != o2 && o3 != o4) { return(true); } return(false); }
// Проверяет, что линия, соединяющая две вершины полигона, не пересекает его стороны bool clearPath(int v0, int v1) { int clockwise, anticlockwise, t0, t1; if (orientation()) { clockwise = 2; anticlockwise = 1; } else { clockwise = 1; anticlockwise = 2; } t0 = v0; t1 = v1; v0 = Math.Min(t0, t1); v1 = Math.Max(t0, t1); LineD line = new LineD(vert[v0], vert[v1]); var test = from v in Enumerable.Range(0, vert.Length) where (v > v0 && v < v1) select line.orientation(vert[v]); for (int v = 0; v < vert.Length; v++) { if (vert[v].X > Math.Min(vert[v0].X, vert[v1].X) && vert[v].Y > Math.Min(vert[v0].Y, vert[v1].Y) && vert[v].X < Math.Max(vert[v0].X, vert[v1].X) && vert[v].Y < Math.Max(vert[v0].Y, vert[v1].Y) && ((v < v0 && line.orientation(vert[v]) == clockwise) || (v > v0 && v < v1 && line.orientation(vert[v]) == anticlockwise) || (v > v1 && line.orientation(vert[v]) == clockwise))) { return(false); } } return(true); }