def coefficients_from_points(p, q):
    """ given 2 points p and q, give the coefficients (a,b,c) for the line
    that runs from p to q: ax + by + c = 0

    when a = 0, then the line is horizontal
    when b = 0, then the line is vertical

    see also: 
    https://www.mathcentre.ac.uk/resources/uploaded/mc-ty-strtlines-2009-1.pdf
    """
    (px, py) = p
    (qx, qy) = q
    # horizontal line
    if py == qy:
        a = 0.
        if qx > px:
            b = 1.
            c = -py
        elif qx == px: # q and p at same x, direction unknown
            b = 0.
            c = 0.
        else:
            b = -1.
            c = py
    # vertical line
    elif qx == px:
        b = 0.
        if qy > py: # q above p
            a = -1.
            c = px
        elif qy == py: # q and p at same y, direction unknown
            a = 0.
            c = 0.
        else:
            a = 1.
            c = -px
    # neither horizontal or vertical
    else:
        a = py - qy
        b = qx - px
        c = -px * a - py * b
    return tuple(map(float, (a, b, c)))