Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

plotting a quadratic graph

Hello everyone.
can someone please help? i am trying to write a program to plot quadratic and line graph given 2 arrays(x,y).
i tried the folowing but its not working.

W = P.Width
H = P.Height
WM = W / 2
HM = H / 2
P.Line (0, HM)-(W, HM), vbRed
P.Line (WM, 0)-(WM, H), vbRed

MAXY = v(0)
For I = 1 To N
If MAXY < v(I) Then
MAXY = v(I)
End If
Next I

MAXX = 5
OX = 0
OY = 0
ScaleX1 = W / N
ScaleY1 = H / N
For I = 0 To N
If v(I) > 0 Then
YT = WM + ((WM * v(I)) / MAXY)
Else
YT = WM - ((WM * -v(I)) / MAXY)
End If
If t(I) > 0 Then
TT = HM + ((HM * t(I)) / MAXX)
Else
TT = HM - ((HM * -t(I)) / MAXX)
End If
OX = OX + ScaleX1
OY = OY + ScaleY1
P.Line -(TT, YT)

Next I
can someone please help?
[937 byte] By [eleniyan] at [2007-11-11 9:58:26]
# 1 Re: plotting a quadratic graph
If it's "quadratic" then "N" must = 3 is it true ?

I just need to know your algorithm to have this shape from array ,
I think line similar to this are not clear :
" YT = WM + ((WM * v(I)) / MAXY) "
After my caluclations this equation generate a "quadratic" form but the problem is to have good matrix .

If u mean that those arrays holds x,y positions so try this will make good work :

WM = p.Width / 2
HM = p.Height / 2
p.Line (0, HM)-(W, HM), vbRed
p.Line (WM, 0)-(WM, H), vbRed

For i = 0 To 3
p.Line -(v(i), t(i))
Next
Amahdy at 2007-11-11 17:23:24 >
# 2 Re: plotting a quadratic graph
I can help you by taking your code and creating a simple test project that plots your graph in a picture box; but I need sample data for the V and T arrays. You should select data that you would recognize what the graph should look like. This way if my results look wrong we can figure out what is throwing it off.
Ron Weller at 2007-11-11 17:24:26 >
# 3 Re: plotting a quadratic graph
Ok I started a simple test project to play around with. It plots the graph and scales it to fit within the picture box. I played around with your code a bit also. Since in VB the X axis is horizontal and the Y axis is veritcal I changed some variable names to refelect this better. Also notice that I set the ScaleMode to pixels so the lines would plot easier. I left your original code in a different sub for reference.
Ron Weller at 2007-11-11 17:25:24 >
# 4 Re: plotting a quadratic graph
well, you are doing too much scaling.
VB is great to plot this kind of data, because you can set the scale (both horizontal and vertical) of the printing/displaying object as you wish, using the scale property.
Just use:

myPictureBox.scale = (MinX, MaxY)-(MaxX, MinY)

where the parameters are the range of your coordinate, minimum and maximum, and you do not have to scale anything, just use your coordinate, for example this draw a rectangle in the middle of the form (code to be used in the Paint event unless the AutoRedraw property was set):

Me.Scale (0, 100)-(100, 0)
Me.Line (25, 25)-Step(50, 50), , B

Incidentally, if you put the drawing code in a sub and you pass to it the Graphic object (like a PictureBox or a Printer) you can implement a Printing app with Preview.

Let us know how it goes
mstraf at 2007-11-11 17:26:29 >