static void DrawBezier(Gdi::Graphics g, Vector2 p1, Vector2 q, Vector2 p2) { const int N = 100; Vector2 pp1 = p1; for (int i = 1; i <= N; i++) { double t = (1.0 / N) * i; Vector2 pp2 = t * t * p2 + 2 * t * (1 - t) * q + (1 - t) * (1 - t) * p1; g.DrawLine(Gdi::Pens.Lime, pp1.ToPointF(), pp2.ToPointF()); pp1 = pp2; } }
public void Draw(Gdi::Graphics g) { g.Clear(Gdi::Color.Transparent); g.DrawLine(Gdi::Pens.Blue, this.p1.ToPointF(), this.q1.ToPointF()); g.DrawLine(Gdi::Pens.Blue, this.p2.ToPointF(), this.q1.ToPointF()); g.DrawLine(Gdi::Pens.Blue, this.p2.ToPointF(), this.q2.ToPointF()); g.DrawLine(Gdi::Pens.Blue, this.p3.ToPointF(), this.q2.ToPointF()); g.DrawLine(Gdi::Pens.Blue, this.p3.ToPointF(), this.q3.ToPointF()); g.DrawLine(Gdi::Pens.Blue, this.p4.ToPointF(), this.q3.ToPointF()); g.DrawLine(Gdi::Pens.Blue, this.p4.ToPointF(), this.q4.ToPointF()); g.DrawLine(Gdi::Pens.Blue, this.p1.ToPointF(), this.q4.ToPointF()); DrawBezier(g, this.p1, this.q1, this.p2); DrawBezier(g, this.p2, this.q2, this.p3); DrawBezier(g, this.p3, this.q3, this.p4); DrawBezier(g, this.p4, this.q4, this.p1); DrawControlPoint(g, this.p1); DrawControlPoint(g, this.p2); DrawControlPoint(g, this.p3); DrawControlPoint(g, this.p4); DrawControlPoint(g, this.q1); DrawControlPoint(g, this.q2); DrawControlPoint(g, this.q3); DrawControlPoint(g, this.q4); }