def parabola_through_three_points(p1, p2, p3):
    """
    Calculates the parabola a*(x-b)+c through three points. The points should be given as (y, x) tuples.
    Returns a tuple (a, b, c)
    """
    # formula taken from http://stackoverflow.com/questions/4039039/fastest-way-to-fit-a-parabola-to-set-of-points
    # Avoid division by zero in calculation of s
    if p2[0] == p3[0]:
        temp = p2
        p2 = p1
        p1 = temp

    s = (p1[0]-p2[0])/(p2[0]-p3[0])
    b = (-p1[1]**2 + p2[1]**2 + s*(p2[1]**2 - p3[1]**2)) / (2*(-p1[1] + p2[1] + s*p2[1] - s*p3[1]))
    a = (p1[0] - p2[0]) / ((p1[1] - b)**2 - (p2[1] - b)**2)
    c = p1[0] - a*(p1[1] - b)**2
    return (a, b, c)