import torch


def transform_viewpoints(v):
    """
    v: viewpoint
    Transforms the viewpoint into suitable representation
    v_hat = [w, cos(y), sin(y), cos(p), sin(p)]
    """

    w, z = torch.split(v, 3, dim=-1)
    y, p = torch.split(z, 1, dim=-1)

    _v = [w, torch.cos(y), torch.sin(y), torch.cos(p), torch.sin(p)]
    v_hat = torch.cat(_v, dim=-1)

    return v_hat