I have three X/Y points that form a parabola. I simply need to calculate what the vertex of the parabola is that goes through these three points. Preferably a quick way as I have to do a LOT of these calculations!

The general form of a parabola is given by the equation: A * x^2 + B * x + C = y where A, B, and C are arbitrary Real constants. You have three pairs of points that are (x,y) ordered pairs. Substitute the x and y values of each point into the equation for a parabola. You will get three LINEAR equations in three unknowns, the three constants. You can then easily solve this system of three equations for the values of A, B, and C, and you'll have the equation of the parabola that intersects your 3 points. The vertex is where the first derivative is 0, a little algebra gives: ( -B/2A , C - B^2/4A ) for the vertex.

It would be nice to see actual code that does this calculation in C# or C++. Anybody?

8 Answers
8

This is really just a simple linear algebra problem, so you can do the calculation symbolically. When you substitute in the x and y values of your three points, you'll get three linear equations in three unknowns.

A x1^2 + B x1 + C = y1
A x2^2 + B x2 + C = y2
A x3^2 + B x3 + C = y3

The straightforward way to solve this is to invert the matrix

x1^2 x1 1
x2^2 x2 1
x3^2 x3 1

and multiply it by the vector

y1
y2
y3

The result of this is... okay, not exactly all that simple ;-) I did it in Mathematica, and here are the formulas in pseudocode:

Loks like you're the only who actually answered the whole question, giving the actual vertex coordinate. It saved me from importing a linalg module in Python (direct arithmetic much better). Thanks!!
–
heltonbikerAug 10 '12 at 14:15

You can solve this by noting that this is equivalent to the matrix product:

[x1^2 x1 1] [A] [y1]
|x2^2 x2 1|*|B| = |y2|
[x3^2 x3 1] [C] [y3]

So you can get A,B, and C by inverting the matrix and multiplying the inverse with the vector on the right.

I see that while I've been posting this John Rasch has linked to tutorial that goes into more depth on actually solving the matrix equation, so you can follow those instructions to get the answer. Inverting a 3x3 matrix is quite easy, so this shouldn't be too tough.