Possible Duplicate:
How to calculate the vertex of a parabola given three points
I have three 2D point P1, P2 and P3, each consisting of a pair of coordinates (Xn, Yn), given that:
- X1 < X2 < X3;
- Y2 < Y1;
- Y2 < Y3;
Geometrically speaking, they form a "V".
What I need is a method of getting the coordinates of the vertex of the parabola passing through the three points, its concavity facing upwards, so as to consider it a local minimum of an insuficiently sampled curve.
I am using Python, and adapted an algorithm found online, but it only appears to work when the left leg of the V is taller. I guess I have made some mistake while adapting it - to avoid some undesired index-dependence behavior of the original algorithm:
def parabolic_interpolation(p1, p2, p3):
x1, y1 = p1
x2, y2 = p2
x3, y3 = p3
dx = x2 - x1
dy = (y3 - y1) * 0.5
d2y = 2 * y2 - y1 - y2
di = dy/d2y
xout = x2 + di * dx
yout = y2 + (dy**2/d2y)*0.5
return (xout,yout)
I am sure the problem of interpolating through three points to find the local minimum (or maximum) is probably already computationally solved, so I would appreciate any help to get it right.
Thanks for reading!