Why won’t this code draw parabola? It is as simple as it can be – for every x calculate y using given function. Given y=x^2 i should draw down facing parabola with vertex in top left corner, yet it only draws some displaced dots.
private void DrawParabole(Graphics g)
{
for (int x = 0; x < pictureBox1.Width; x++)
{
g.DrawRectangle(
Pens.Black,
x,
FY(x),
1,
1
);
}
}
private int FY(int x)
{
int y = A*x^2 + B*x + C;
return y;
}
The reason you are getting the wrong values/scattered dots is because you are using the
XORor^operator instead ofMath.Pow().In order to calculate, lets say,
A*x^2you must use Math.Pow() and not^:That should solve it for you, if it doesn’t then use this:
Hope this helps!