def closest_point(lx, ly, dx, dy, px, py):
    """
    Calculate the closest point to (px,py) on the line (lx,ly) + t*(dx,dy)
    :param lx:
    :param ly:
    :param dx:
    :param dy:
    :param px:
    :param py:
    :return:
    """
    mx = px - lx
    my = py - ly
    den = dx * dx + dy * dy
    nom = mx * dx + my * dy
    tt = nom / den if den != 0 else 0
    return lx + tt * dx, ly + tt * dy, tt
