coords.Coords.spherical_to_cartesian#
- Coords.spherical_to_cartesian(dir=(0, 1, 2), scale=(1.0, 1.0, 1.0), angle_spec=0.017453292519943295, colat=False)#
Convert from spherical to cartesian coordinates.
Consider a spherical coordinate system with the global xy-plane as its equatorial plane and the z-axis as axis. The zero meridional halfplane is taken along the positive x-axis. The spherical coordinates of a point are:
the longitude (theta): the circumferential angle, measured around the z-axis from the zero-meridional halfplane to the meridional plane containing the point: this angle normally ranges from -180 to +180 degrees (or from 0 to 360);
the latitude (phi): the elevation angle of the point’s position vector, measured from the equatorial plane, positive when the point is at the positive side of the plane: this angle is normally restricted to the range from -90 (south pole) to +90 (north pole);
the distance (r): the radial distance of the point from the origin: this is normally positive.
This function interpretes the 3 coordinates of the points as (theta,phi,r) values and computes the corresponding global cartesian coordinates (x,y,z).
Parameters#
- dir: tuple of 3 ints, optional
If provided, it is a permutation of (0,1,2) and specifies which of the current coordinates are interpreted as resp. longitude (theta), latitude (phi) and distance (r). This allows the axis to be aligned with any of the global axes. Default order is (0,1,2). Beware that using a permutation that is not conserving the order of the globale axes (0,1,2), may lead to a confusing left-handed system.
- scale: tuple of 3 floats, optional
Scaling factors that are applied on the coordinate values prior to making the conversion from spherical to cartesian coordinates. These factors are always given in the order (theta,phi,r), irrespective of the permutation by dir.
- angle_spec: float, at.DEG or RAD, optional
Multiplication factor for angle coordinates. The default (at.DEG) interpretes the angles in degrees. Use RAD to specify the angles in radians.
- colat: bool
If True, the second coordinate is the colatitude instead. The colatitude is the angle measured from the north pole toward the south. In degrees, it is equal to
90 - latitudeand ranges from 0 to 180. Applications that deal with regions around the pole may benefit from using this option.
Returns#
- Coords
The global coordinates of the points that were specified with spherical coordinates as input.
See Also#
cartesian_to_spherical(): the inverse transformation (cartesian to spherical)cylindrical_to_cartesian(): similar function for cylindrical coordinates
Examples#
>>> X = Coords([[0., 0., 1.],[90., 0., 1.],[90., 90., 1.],[0., 90., 1.]]) >>> X.spherical_to_cartesian() Coords([[ 1., 0., 0.], [-0., 1., 0.], [-0., 0., 1.], [ 0., 0., 1.]])
Note that the last two points, though having different spherical coordinates, are coinciding at the north pole.