/// <summary> /// Triagulate a polygon using the 'clipping ear' theorem /// see: http://www-cgrl.cs.mcgill.ca/~godfried/teaching/cg-projects/97/Ian/algorithm2.html /// </summary> /// <param name="p"></param> /// <returns></returns> public static Triangle[] Triangulate(Polygon p) { List<Triangle> triList = new List<Triangle>(); // Make sure the points are ordered clockwise, else this method will fail List<Point2D> points = Point2D.SortPoints(true, Point2D.DeepCopy(p.points)); // Search for an ear for as long as this polygon isn't reduced to a triangle itself while (points.Count > 3) for (int i = 0; i < points.Count; i++) { Point2D p1 = points[i]; Point2D p2 = points[(i + 1) % points.Count]; Point2D p3 = points[(i + 2) % points.Count]; Triangle t; if (Polygon.IsEar(p1, p2, p3, points, out t)) { triList.Add(t); break; } } // Add the remaining 3 points as a triangle triList.Add(new Triangle(points[0], points[1], points[2])); return triList.ToArray(); }
public PolygonR(Polygon po) { PointF[] p = new PointF[po.Points.Length]; for (int i = 0; i < po.Points.Length; i++) { p[i] = new PointF((float)po.Points[i].X, (float)po.Points[i].Y); } Points = p; }