def cartesian_to_spherical(x, y, z):
 if (not hasattr(x, u'unit')):
  x = (x * u.dimensionless_unscaled)
 if (not hasattr(y, u'unit')):
  y = (y * u.dimensionless_unscaled)
 if (not hasattr(z, u'unit')):
  z = (z * u.dimensionless_unscaled)
 cart = CartesianRepresentation(x, y, z)
 sph = cart.represent_as(SphericalRepresentation)
 return (sph.distance, sph.lat, sph.lon)

def cartesian_to_spherical ( x , y , z ) : if ( not hasattr ( x , u'unit' ) ) : x = ( x * u . dimensionless_unscaled ) if ( not hasattr ( y , u'unit' ) ) : y = ( y * u . dimensionless_unscaled ) if ( not hasattr ( z , u'unit' ) ) : z = ( z * u . dimensionless_unscaled ) cart = CartesianRepresentation ( x , y , z ) sph = cart . represent_as ( SphericalRepresentation ) return ( sph . distance , sph . lat , sph . lon )
converts 3d rectangular cartesian coordinates to spherical polar coordinates .