def OnSegment(P1, P2, P3):
    """
    Check if P3 is on line P1 - P2.

    Parameters
    ----------
    P1 : 1D numpy array, floats
        x- and y-coordinates of point. Part of the line.
    P2 : TYPE
        x- and y-coordinates of point. Part of the line.
    P3 : TYPE
        x- and y-coordinates of point. To be checked if on line.
    Returns
    -------
    bool
        True if on segment, False if not.

    Source
    -------
    https://stackoverflow.com/questions/328107/how-can-you-determine-a-point-is-between-two-other-points-on-a-line-segment/29301940#29301940
    """
    X1, Y1 = P1
    X2, Y2 = P2
    X3, Y3 = P3
    crossproduct = (Y3 - Y2) * (X2 - X1) - (X3 - X1) * (Y2 - Y1)

    if abs(crossproduct) != 0:
        return False

    dotproduct = (X3 - X1) * (X2 - X1) + (Y3 - Y1) * (Y2 - Y1)
    if dotproduct < 0:
        return False

    squaredlengthba = (X2 - X1) * (X2 - X1) + (Y2 - Y1) * (Y2 - Y1)
    if dotproduct > squaredlengthba:
        return False

    return True