usingMaths.com
Demonstrating and showing pupils and students one application of Mathematics.







<< PreviousNext >>

Code to Animate an Image Body through a Quadratic Curve in C#



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.

Quadratic Curve

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.

Quadratic Points

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

Hence:
a   =    ystart - ymax  =  ystart - ymax
xstart2 - 2xmaxxstart + xmax2 (xstart - xmax)2

b = -2axmax
       & from (eqn *)
c = ymax + axmax2



Code to Animate a Graphic Object through a Quadratic Curve in C#

To make a graphic (dot) travel by the equation of a quadratic curve, continuously increment x by some interval, and use the equation to get the corresponding y value.
.

Create a class;
Call it QuadraticPath.
Type out the adjoining C# code for animating an image body through the path of a quadratic curve.









<< PreviousNext >>