def linecoef(p1, p2):
    """
    Coefficients A, B, C of line equation (Ax + By = C) from
    the two endpoints p1, p2 of the line

    Input: p1, p2 the two points (x, y) of the line segment

    Output: Coefficients of the line equation
    """
    # ref: https://stackoverflow.com/questions/20677795/
    #      how-do-i-compute-the-intersection-point-of-two-lines-in-python

    A = (p1[1] - p2[1])
    B = (p2[0] - p1[0])
    C = (p1[0] * p2[1] - p2[0] * p1[1])
    return A, B, -C