import torch


def get_3d_box(tensor):
    """Calculate 3D bounding box corners from its parameterization.
    Input:
        box_size: tuple of (length,wide,height)
        heading_angle: rad scalar, clockwise from pos x axis
        center: tuple of (x,y,z)
    Output:
        corners_3d: numpy array of shape (8,3) for 3D box cornders
    """
    center = tensor[3:6]
    l,h,w = tensor[:3]
    heading_angle = tensor[-1]

    def roty(t):
        c = torch.cos(t)
        s = torch.sin(t)
        return torch.tensor([[c, 0, s], [0, 1, 0], [-s, 0, c]])

    R = roty(heading_angle)
    x_corners = torch.tensor([l / 2, l / 2, -l / 2, -l / 2, l / 2, l / 2, -l / 2, -l / 2])
    y_corners = torch.tensor([h / 2, h / 2, h / 2, h / 2, -h / 2, -h / 2, -h / 2, -h / 2])
    z_corners = torch.tensor([w / 2, -w / 2, -w / 2, w / 2, w / 2, -w / 2, -w / 2, w / 2])
    corners_3d = torch.mm(R, torch.vstack([x_corners, y_corners, z_corners]))
    corners_3d[0, :] = corners_3d[0, :] + center[0]
    corners_3d[1, :] = corners_3d[1, :] + center[1]
    corners_3d[2, :] = corners_3d[2, :] + center[2]
    corners_3d = corners_3d.transpose(-1,-2)
    return corners_3d