import torch


def obb2hbb(obboxes):
    """Convert oriented bounding boxes to horizontal bounding boxes.

    Args:
        obboxes (torch.Tensor): [x_ctr,y_ctr,w,h,angle]
    Returns:
        hbbs (torch.Tensor): [x_lt,y_lt,x_rb,y_rb]
    """
    center, w, h, theta = torch.split(obboxes, [2, 1, 1, 1], dim=1)
    Cos, Sin = torch.cos(theta), torch.sin(theta)
    x_bias = torch.abs(w / 2 * Cos) + torch.abs(h / 2 * Sin)
    y_bias = torch.abs(w / 2 * Sin) + torch.abs(h / 2 * Cos)
    bias = torch.cat([x_bias, y_bias], dim=1)
    return torch.cat([center - bias, center + bias], dim=1)