def point_seg_sep(ar, br1, br2):
    """Return the minimum separation vector between a point and a line segment,
    in 3 dimensions.

    Parameters
    ----------
    ar: array-like, shape (3,)
        Coordinates of a point.
    br1, br2: array-like, shape (3,)
        Coordinates for the points of a line segment

    Returns
    -------
    sep: float array, shape (3,)
        Separation vector between point and line segment.
    """
    v = br2 - br1
    w = ar - br1

    c1 = np.dot(w, v)
    if c1 <= 0.0:
        return ar - br1

    c2 = np.sum(np.square(v))
    if c2 <= c1:
        return ar - br2

    b = c1 / c2
    bc = br1 + b * v
    return ar - bc
Return the minimum separation vector between a point and a line segment,
    in 3 dimensions.

    Parameters
    ----------
    ar: array-like, shape (3,)
        Coordinates of a point.
    br1, br2: array-like, shape (3,)
        Coordinates for the points of a line segment

    Returns
    -------
    sep: float array, shape (3,)
        Separation vector between point and line segment.