import torch


def spherical_to_cartesian(theta, phi, radius=1.0):
    """
    Converts from spherical coordinates to cartesian coordinates. Spherical coordinates
    are defined according to the physics convention (theta elevation, phi azimuth).

    https://en.wikipedia.org/wiki/Spherical_coordinate_system#Cartesian_coordinates

    Args:
        theta (tensor): elevation.
        phi (tensor): azimuth.
        radius (tensor): radius. Defaults to 1.

    Returns:
        (x, y, z)
    """
    x = radius * torch.sin(theta) * torch.cos(phi)
    y = radius * torch.sin(theta) * torch.sin(phi)
    z = radius * torch.cos(theta)
    return x, y, z