cart2sph

Converts Cartesian coordinates to spherical coordinates.

Category: Mathematics > Elementary Math

Syntax

[az, el, r] = cart2sph(x, y, z)

Returns azimuth, elevation and radius of each point.

Description

The conversion is az = atan2(y, x), el = atan2(z, sqrt(x.^2 + y.^2)) and r = sqrt(x.^2 + y.^2 + z.^2). Elevation is measured from the equator, not from the pole, so a point on the xy-plane has el = 0. The inverse is sph2cart.

Input arguments

x, y, z
Arrays of equal size (or scalars) with the Cartesian coordinates.

Output arguments

az
Azimuth: angle in the xy-plane from the positive x-axis, in radians, in [-pi, pi].
el
Elevation: angle above the xy-plane, in radians, in [-pi/2, pi/2].
r
Distance from the origin.

Example

Spherical coordinates of (1, 1, 1)

[az, el, r] = cart2sph(1, 1, 1)
Output
az = 0.7854
el = 0.6155
r = 1.7321

Notes

MatLivre requires x, y and z as separate arguments; the single-matrix form is not supported.

See also

sph2cart cart2pol atan2