Draw a curve?

Star_T
06-02-2004, 04:38 AM
how can I draw this in a picturebox???
y=3x²+2x+4

Iceplug
06-02-2004, 08:16 AM
Use a For Loop.

For X = 0 To PB.Width
'All values of pixels that fit nicely in the picturebox.
Y = 3 * X * X + 2 * X + 4
'Function.
GFXofPB.DrawLine(Pens.Black, Xold, Yold, X, Y)
'Draw a line connecting the two points.
Next

That'll just draw the positive part, and require a really tall textbox and a small width.
For drawing part of the functions for negative values and for scaling, you'll need two more X and Y variables to go with the X and Y above... use one pair to determine where the line point will be drawn and the other pair to determine what the actual values are going to be used for X and Y. :)

I discussed it in this thread (where I use GetPixel and SetPixel):
http://www.xtremevbtalk.com/showthread.php?t=101869&highlight=Plotting+function

P.S. For doing lines, you need to store the old position of the line, unless you use GFXtoPB.DrawLines() and store all of the function points into an array.

Star_T
06-08-2004, 10:01 AM
Thanks for that.
and one mor question
can I change coordinate system.
y values increase downwards
Is it posible to increase yvalues upwards. like real coordinate system

Iceplug
06-08-2004, 10:40 AM
Oh... sure.
You can do something like this:

Pretend that Y is the result that you got from the function...
to make positive Y go up, you need to make Y negative. Then, if you add PB.Width, zero will be at the bottom of the picturebox. :)
GY = PB.Width - Y
That will put Y = 0 at the bottom of the textbox, and it will go to the top when Y increases. :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum