import torch


def xyz2betagamma(x, y, z):
    """
    Return new tensors corresponding to angle representation from the cartesian representation.

    Warning: x, y, z have to be on the 1-sphere.

    Args:
        x (`torch.FloatTensor`): x positions.
        y (`torch.FloatTensor`): y positions.
        z (`torch.FloatTensor`): z positions.

    Returns:
        (`torch.FloatTensor`): beta rotations about y axis.
        (`torch.FloatTensor`): gamma rotations about z axis.
    """
    beta = torch.acos(z)
    gamma = torch.atan2(y, x)
    return beta, gamma