import torch


def vec_pts_to_line_torch(pts, ptlines, vlines):
    """ Normal vector from a point to a line.

        Arguments:
            - pts - [N, D] - N D-dimensional points
            - ptlines - [N, D] - points on the lines
            - vlines - [N, D] - vectors of the lines, not necessarily normalized
        
        Returns:
            - [N, D] - shortest vectors from the N points to the lines (unnormalized)
    """
    a = torch.sum(vlines * (pts - ptlines), dim=-1) / torch.sum(vlines * vlines, dim=-1)
    res = a[:, None] * vlines + ptlines - pts
    return res