def Sphere2xyz(coords, lam=None, phi=None):
    """Compute (x,y,z) from coords=(r,lam,phi) or r,lam,phi, where lam=0 at the Equator, -90 <= lam <= 90 (latitude),
        and phi=0 along x-axis, 0 <= phi <= 360 (longitude)
        Also computes the normal along the radial direction (useful for placing and orienting the camera).

        INPUTS:
            coords - list of (radius,lambda,phi) or radius
            lam    - lambda (declination, latitude) if coords is radius
            phi    - phi (azimuth, longitude) if coords is radius
        OUTPUTS:
            xyzPos - list of corresponding (x,y,z)
            normal - list of (xn,yn,zn) along radial direction
    """
    from math import pi, sin, cos
    if isinstance(coords, list) or isinstance(coords, tuple):
        if len(coords) == 3:
            rr = coords[0]
            lam = coords[1]
            phi = coords[2]
        else:
            raise Exception(
                'Sphere2xyz: coords has to be a list of length 3 (r,lambda,phi), or a scalar'
                )
    else:
        rr = coords
    xyzPos = [rr * cos(lam * pi / 180) * cos(phi * pi / 180), rr * cos(lam *
        pi / 180) * sin(phi * pi / 180), rr * sin(lam * pi / 180)]
    rr = rr + 1
    p1 = [rr * cos(lam * pi / 180) * cos(phi * pi / 180), rr * cos(lam * pi /
        180) * sin(phi * pi / 180), rr * sin(lam * pi / 180)]
    normal = []
    for i in range(len(p1)):
        normal.append(p1[i] - xyzPos[i])
    return xyzPos, normal
