// ALGORITHMS private void findIntersections() { PointF pol1center, pol2center; sortPointsClockwise(ref polygon1, out pol1center); sortPointsClockwise(ref polygon1, out pol2center); var pol1 = new PolyNode[polygon1.Count + 1]; var pol2 = new PolyNode[polygon2.Count + 1]; polygon1.CopyTo(pol1, 0); polygon2.CopyTo(pol2, 0); pol1[polygon1.Count] = pol1.First(); pol2[polygon2.Count] = pol2.First(); for (int i = 0; i < pol1.Count() - 1; ++i) { for (int j = 0; j < pol2.Count() - 1; ++j) { PointF intersection_point = findIntersection(pol1[i].p, pol1[i + 1].p, pol2[j].p, pol2[j + 1].p); if (intersection_point.X != -1) { PolyNode ip1 = new PolyNode(intersection_point, true); PolyNode ip2 = new PolyNode(intersection_point, true); var t1 = polygon1.Find(pol1[i]); while (t1.Next != null && t1.Next.Value.isIntersection && distance(pol1[i + 1].p, t1.Next.Value.p) > distance(pol1[i + 1].p, ip1.p)) { t1 = t1.Next; } var n1 = polygon1.AddAfter(t1, ip1); var t2 = polygon2.Find(pol2[j]); while (t2.Next != null && t2.Next.Value.isIntersection && distance(pol2[j + 1].p, t2.Next.Value.p) > distance(pol2[j + 1].p, ip2.p)) { t2 = t2.Next; } var n2 = polygon2.AddAfter(t2, ip2); n1.Value.otherNode = n2; n2.Value.otherNode = n1; } } } }