Friday, August 31, 2007

Using graphics in C#.NET to explore slope fields

Lately, I’ve been working on Calculus and the topic of slope fields has come up. Here is a good introduction to Slope Fields and why they’re important.
http://calculuslab.deltacollege.edu/ODE/7-1/7-1-0-h.html
So, I want to graph my own slope fields using C#.NET. I haven’t done any graphing applications in .NET yet but after doing some research I found that it is pretty easy. First, create a Visual Studio C# applications project. Then get an event into the application by going to the form properties, events section and double clicking on the Paint section to create a function called Form1_Paint. Then put code into the function to draw a line:

private void Form1_Paint(object sender, PaintEventArgs e)
{

Graphics g = e.Graphics;
Pen pn = new Pen(Color.Blue);
Point pt1 = new Point(30, 30);
Point pt2 = new Point(110, 100);
g.DrawLine(pn, pt1, pt2);

}

The graphics package for C#.NET is called GDI+ and the classes I’m using here are from System.Drawing.
I’m going to attempt to write a C#.NET application to draw and explore slope fields. I’ll put the code up on my website when I finish it.
Cheers,
Alex

No comments: