public List <clsPoint> Intersect(clsLine l1, bool sortByDistToL1P1 = false) { List <clsPoint> myPts = new List <clsPoint>(); int i; int j; clsLine l2; clsPoint p1; double d1; double d2; for (i = 0; i <= NumPoints; i++) { j = i + 1; if (j > NumPoints) { j = 0; } l2 = new clsLine(Point(i), Point(j)); p1 = l1.IntersectShortLine1(l2); if (p1 != null) { myPts.Add(p1); } } if (sortByDistToL1P1) { for (i = 0; i <= myPts.Count - 2; i++) { d1 = myPts[i].Dist(l1.P1); for (j = i + 1; j <= myPts.Count - 1; j++) { d2 = myPts[j].Dist(l1.P1); if (d2 < d1) { p1 = myPts[i]; myPts[i] = myPts[j]; myPts[j] = p1; } } } } return(myPts); }