import torch


def get_inside_points(points1, points2, parts=2):
    """
    Build 2D line segment between start points, with a specified number of intermediate points.
    :param points1: Tensor of shape (batch, 2), starting points
    :param points2: Tensor of shape (batch, 2), ending points
    :param parts: when building the line segments that unite the two points of consecutive instants, how many
    intermediate points will be included (this excludes start and end of the segment)
    :return: Tensor of shape (batch,2,parts+2). Equally distanced points between starting and ending "control" points
    """
    points = torch.zeros(points1.shape[0], points1.shape[1], parts + 2, device=points1.device)
    for i, (p1, p2) in enumerate(zip(points1, points2)):
        points[i, :, :] = torch.cat((torch.linspace(p1[0], p2[0], parts + 2, device=points.device).unsqueeze(0),
                                     torch.linspace(p1[1], p2[1], parts + 2, device=points.device).unsqueeze(0)), dim=0)
    return points