/// <summary> /// Draws an ovoid: a closed Catmull-Rom spline. /// </summary> /// <param name="pts">Control Points</param> /// <param name="fillStr">Fill color</param> /// <param name="outlineStr">Outline color</param> public void DrawOvoid(String fillStr, String outlineStr, Path pts ) { int numPts = pts.Count(); Path final = new Path(); for (int i = 0; i < numPts; i++) { Point2D P0 = pts[(i - 1 + numPts) % numPts]; Point2D P1 = pts[i]; Point2D P2 = pts[(i + 1) % numPts]; Point2D P3 = pts[(i + 2) % numPts]; for (int j = 0; j < resolution; j++) { double t = (double)j / resolution; final.AddPt( 0.5 * ((2.0 * P1) + (-P0 + P2) * t + (2 * P0 - 5 * P1 + 4 * P2 - P3) * t * t + (-P0 + 3 * P1 - 3 * P2 + P3) * t * t * t) ); } } DrawPoly(fillStr, outlineStr, final); }
/// <summary> /// Draws a closed form with N splines /// The last point of spline N should be the same as the first point of spline N+1 /// </summary> /// <param name="splines">The control points for the top spline</param> /// <param name="bottom">The control points for the top spline</param> /// <param name="fillStr">Color to fill the figure</param> /// <param name="outlineStr">Color to outline the figure</param> public void DrawPaths( String fillStr, String outlineStr, params Path[] splines) { Path final = new Path(); foreach (Path spline in splines) { for (int i = 0; i < spline.Count() - 1; i++) { Point2D P0 = (i == 0) ? spline[0] + spline[0] - spline[1] : spline[i - 1]; Point2D P1 = spline[i]; Point2D P2 = spline[i + 1]; Point2D P3 = (i == spline.Count() - 2) ? spline[i + 1] + spline[i + 1] - spline[i] : spline[i + 2]; for (int j = 0; j < resolution; j++) { double t = (double)j / resolution; final.AddPt( 0.5 * ((2.0 * P1) + (-P0 + P2) * t + (2 * P0 - 5 * P1 + 4 * P2 - P3) * t * t + (-P0 + 3 * P1 - 3 * P2 + P3) * t * t * t) ); } } } DrawPoly(fillStr, outlineStr, final ); }