Using the Equation of a Quadratic Curve in C++
The equation of a quadratic curve has the general form
y = ax2 + bx + c;
where a, b, c are constants.
Generating Quadratic Curves for C++
To generate a quadratic curve, all we will need is a starting point and the maximum / minimum (highest / lowest) point of the curve.
y = ax2 + bx + c
dy/dx = yI = 2ax + b
At maximum / minimum point, yI = 0
yI|(x = xmax) = 0
2axmax + b = 0
b = -2axmax
Substituting b in the general equation
y = ax2 + bx + c
= ax2 - 2axmaxx + c
At (xstart, ystart):
ystart = axstart2 - 2axmaxxstart + c
At (xmax, ymax):
ymax = axmax2 - 2axmax2 + c
= -axmax2 + c
--------- (eqn *)
Subtracting both derived equations
ystart - ymax =
axstart2 - 2axmaxxstart
+ axmax2
(xstart2 - 2xmaxxstart
+ xmax2)a = ystart - ymax
a = | ystart - ymax | = | ystart - ymax |
xstart2 - 2xmaxxstart + xmax2 | (xstart - xmax)2 |
b = -2axmax
& from (eqn *)
c = ymax + axmax2