You can use GDI+ to draw curves in .NET framework. GDI+ supports several types of curves: ellipses, arcs, cardinal splines, and Bézier splines.
------Bell shaped cardinal spline------
Point[] points = {
new Point(0, 100),
new Point(50, 80),
new Point(100, 20),
new Point(150, 80),
new Point(200, 100)};
Pen pen = new Pen(Color.FromArgb(255, 0, 0, 255));
e.Graphics.DrawCurve(pen, points);
-----Closed Cardinal Spline-----
Point[] points = {
new Point(60, 60),
new Point(150, 80),
new Point(200, 40),
new Point(180, 120),
new Point(120, 100),
new Point(80, 160)};
Pen pen = new Pen(Color.FromArgb(255, 0, 0, 255));
e.Graphics.DrawClosedCurve(pen, points);
------Single Bézier Spline -----
Point p1 = new Point(10, 100); // Start point
Point c1 = new Point(100, 10); // First control point
Point c2 = new Point(150, 150); // Second control point
Point p2 = new Point(200, 100); // Endpoint
Pen pen = new Pen(Color.FromArgb(255, 0, 0, 255));
e.Graphics.DrawBezier(pen, p1, c1, c2, p2);
-------Sequence of Bézier Splines -------
Point[] p = {
new Point(10, 100), // start point of first spline
new Point(75, 10), // first control point of first spline
new Point(80, 50), // second control point of first spline
new Point(100, 150), // endpoint of first spline and
// start point of second spline
new Point(125, 80), // first control point of second spline
new Point(175, 200), // second control point of second spline
new Point(200, 80)}; // endpoint of second spline
Pen pen = new Pen(Color.Blue);
e.Graphics.DrawBeziers(pen, p);
2006-10-10 02:02:16
·
answer #1
·
answered by Utkarsh 6
·
0⤊
0⤋
Here is a quick example, play around with the code..
private void button3_Click(object sender, System.EventArgs e)
{
using (Graphics grf = CreateGraphics())
{
grf.Clear(Color.White);
// create points for the cardinal spline curve
Point[] pts = new Point[]
{
new Point(10, 210),
new Point(150, 300),
new Point(300, 270),
new Point(220, 220)
};
// Draw the same curve with different tension values
grf.DrawCurve(Pens.Black, pts, 1.0f);
grf.DrawCurve(Pens.Red, pts, 0.0f);
grf.DrawCurve(Pens.Blue, pts, 2.0f);
}
}
2006-10-09 23:56:21
·
answer #2
·
answered by Asher 3
·
1⤊
0⤋