## 16-07-2014 Points on a Parabola

You can try it out here with this JavaScript version of the code. A modern-ish browser required, as it uses an HTML5 canvas.

A couple of years ago, I wrote a simple program in C that lets you drag three different points around on the screen. These points would be used to calculate a parabola that they all lie on, and plot that parabola on the screen. The algebra used in working out the function for the parabola is relatively easy to do, and that is the subject of this blog.

As you may recall, a parabola can be represented using a quadratic equation:

^{2}+ bx + c

The work then is pretty straightforward. We'll take the x and y coordinates of any three points (where no two have the same x value), and plug each pair of values into the equation above. With each of them we can solve for either a, b or c. Once we have any of those three terms calculated, we'll substitute it into one of our other solutions, eliminating that variable. Repeating this process will eliminate all three of them, defining them strictly in terms of our three given points.

The points in this case will be defined as **(x _{1},
y_{1})**,

**(x**. and

_{2}, y_{2})**(x**. We'll start with the simplest one, solving for c:

_{3}, y_{3})_{1}= ax

_{1}

^{2}+ bx

_{1}+ c

_{1}- ax

_{1}

^{2}- bx

_{1}

Next we'll solve for b, by using (x_{2}, y_{2}) for
our x and y values, while replacing c with the equation above

_{2}= ax

_{2}

^{2}+ bx

_{2}+ c

_{2}= ax

_{2}

^{2}+ bx

_{2}+ (y

_{1}- ax

_{1}

^{2}- bx

_{1})

_{2}- bx

_{1}= y

_{2}- ax

_{2}

^{2}+ ax

_{1}

^{2}- y

_{1}

_{2}- x

_{1}) = y

_{2}- a(x

_{2}

^{2}- x

_{1}

^{2}) - y

_{1}

_{2}- x

_{1}) = y

_{2}- y

_{1}- a(x

_{2}- x

_{1})(x

_{2}+ x

_{1})

_{2}- y

_{1}

_{2}- x

_{1}

_{2}+ x

_{1})

Now we have a solution for c given b and a, and a solution for b given a. Next we'll find our solution for a, and put the whole thing together.

_{3}= ax

_{3}

^{2}+ bx

_{3}+ c

_{3}= ax

_{3}

^{2}+ bx

_{3}+ (y

_{1}- ax

_{1}

^{2}- bx

_{1})

_{3}= ax

_{3}

^{2}- ax

_{1}

^{2}+ bx

_{3}- bx

_{1}+ y

_{1}

_{3}

^{2}- x

_{1}

^{2}) + b(x

_{3}- x

_{1}) = y

_{3}- y

_{1}

_{3}- x

_{1})(x

_{3}+ x

_{1}) + b(x

_{3}- x

_{1}) = y

_{3}- y

_{1}

_{3}+ x

_{1}) + b =

_{3}- y

_{1}

_{3}- x

_{1}

_{3}+ x

_{1}) +

_{2}- y

_{1}

_{2}- x

_{1}

_{2}+ x

_{1})

_{3}- y

_{1}

_{3}- x

_{1}

_{3}+ x

_{1}- x

_{2}- x

_{1}) =

_{3}- y

_{1}

_{3}- x

_{1}

_{2}- y

_{1}

_{2}- x

_{1}

_{3}- x

_{2}) =

_{3}- y

_{1})(x

_{2}- x

_{1}) - (y

_{2}- y

_{1})(x

_{3}- x

_{1})

_{3}- x

_{1})(x

_{2}- x

_{1})

_{3}- y

_{1})(x

_{2}- x

_{1}) - (y

_{2}- y

_{1})(x

_{3}- x

_{1})

_{3}- x

_{1})(x

_{2}- x

_{1})(x

_{3}- x

_{2})

_{2}y

_{3}- x

_{1}y

_{3}- x

_{2}y

_{1}+ x

_{1}y

_{1}- x

_{3}y

_{2}+ x

_{1}y

_{2}+ x

_{3}y

_{1}- x

_{1}y

_{1}

_{3}

^{2}x

_{2}- x

_{3}x

_{2}

^{2}- x

_{3}

^{2}x

_{1}+ x

_{1}x

_{2}x

_{3}- x

_{1}x

_{2}x

_{3}+ x

_{1}x

_{2}

^{2}+ x

_{1}

^{2}x

_{3}- x

_{1}

^{2}x

_{2}

_{1}(x

_{3}- x

_{2}) + y

_{2}(x

_{1}- x

_{3}) + y

_{3}(x

_{2}- x

_{1})

_{1}

^{2}(x

_{3}- x

_{2}) + x

_{2}

^{2}(x

_{1}- x

_{3}) + x

_{3}

^{2}(x

_{2}- x

_{1})

And now we have our three coefficients, and can use our original quadratic equation to calculate the y co-ordinate of any point on the curve given its x co-ordinate.