Need help drawing tangent, log, and exponent curves (C# but somewhat language independant)
Author |
Message |
WilliamsD
|
Posted: Sat Apr 14, 2007 3:16 pm Post subject: Need help drawing tangent, log, and exponent curves (C# but somewhat language independant) |
|
|
Long story short, my class assignment is to make a graphing program in C# that draws sin, tangent, log, and exponent curves. My problem stems from the fact that I have had a serious lack of math instruction and don't know how to do this.
I have the sin curve finished from an in-class example we were given, but I don't know where to begin on the others.
Here is the code for the sin curve if it helps:
code: |
g.Clear(Color.Black); // 'g' = graphics object
DrawAxis(g); //Function I wrote, draws the axis on the graph as you would imagine
for (int i = 0; i < this.Width; i++) // "this" refers to the custom graph control that this code is in
{
double x = (i - this.ptOrigin.X);
double y = Math.Sin(x);
Points[i] = new Point(Convert.ToInt32(x + ptOrigin.X), Convert.ToInt32(y + ptOrigin.Y)); // "ptOrigin" is the center of my graph, used to offset the curve's location
}
//Scale up size for visibility
g.ScaleTransform(2, 2);
g.DrawCurve(p, Points);
g.ResetTransform();
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
ericfourfour
|
Posted: Sat Apr 14, 2007 4:11 pm Post subject: RE:Need help drawing tangent, log, and exponent curves (C# but somewhat language independant) |
|
|
I imaging you would treat the screen as a Cartesian plane and simply graph each function.
I really don't know what all of these functions would look like but I'm going to guess:
sine: f(x) = sin(x)
tangent: f(x) = tan(x)
log: f(x) = log(x)
exponent: f(x) = a^x
Just plug numbers into those functions to get the y. Plain and simple. |
|
|
|
|
|
klopyrev
|
Posted: Sat Apr 14, 2007 7:41 pm Post subject: Re: Need help drawing tangent, log, and exponent curves (C# but somewhat language independant) |
|
|
Its as simple as replacing the line:
double y = Math.Sin(x);
with one of:
double y = Math.Sin(x);
double y = Math.Tan(x);
double y = Math.Log(x); or double y = Log(a,x); (The first one is base E, second is base a)
double y = Math.Pow(a,x); (Base a) |
|
|
|
|
|
|
|