import torch


def dist_point_to_line(p1, p2, x0, y0):
    """
    https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line
    Line defined by P1=(x1,y1), P2=(x2,y2)
    Point defined by P0=(x0, y0)
    """
    x1, y1 = p1.unbind(2)
    x2, y2 = p2.unbind(2)
    nom = torch.abs((y2 - y1) * x0 - (x2 - x1) * y0 + x2 * y1 - y2 * x1)
    denom = torch.sqrt((y2 - y1) ** 2 + (x2 - x1) ** 2)

    return nom / denom