0

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:

  1. X1 < X2 < X3;
  2. Y2 < Y1;
  3. 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!

Community
  • 1
  • 1
heltonbiker
  • 26,657
  • 28
  • 137
  • 252
  • 1
    take a look at this [question](http://stackoverflow.com/questions/717762/how-to-calculate-the-vertex-of-a-parabola-given-three-points) – Xantix Aug 10 '12 at 01:59
  • @Xantix Amazing! I vote to close my own question as an exact duplicate! Thank you so much! – heltonbiker Aug 10 '12 at 02:07

0 Answers0