stylistic:tone, structural:scholar_edition
Cartesian coordinates

The spherical coordinates of a point in the ISO convention (i.e. for physics: radius r, inclination θ, azimuth φ) can be obtained from its Cartesian coordinates (x, y, z) by the formulae

r = x 2 + y 2 + z 2 θ = arccos z x 2 + y 2 + z 2 = arccos z r = { arctan x 2 + y 2 z if z > 0 π + arctan x 2 + y 2 z if z < 0 + π 2 if z = 0 and x 2 + y 2 ≠ 0 undefined if x = y = z = 0 φ = sgn (y) arccos x x 2 + y 2 = { arctan (y x) if x > 0, arctan (y x) + π if x < 0 and y ≥ 0, arctan (y x) − π if x < 0 and y < 0, + π 2 if x = 0 and y > 0, − π 2 if x = 0 and y < 0, undefined if x = 0 and y = 0. {\displaystyle {\begin{aligned}r&={\sqrt {x^{2}+y^{2}+z^{2}}}\\\theta &=\arccos {\frac {z}{\sqrt {x^{2}+y^{2}+z^{2}}}}=\arccos {\frac {z}{r}}={\begin{cases}\arctan {\frac {\sqrt {x^{2}+y^{2}}}{z}}&{\text{if }}z>0\\\pi +\arctan {\frac {\sqrt {x^{2}+y^{2}}}{z}}&{\text{if }}z<0\\+{\frac {\pi }{2}}&{\text{if }}z=0{\text{ and }}{\sqrt {x^{2}+y^{2}}}\neq 0\\{\text{undefined}}&{\text{if }}x=y=z=0\\\end{cases}}\\\varphi &=\operatorname {sgn}(y)\arccos {\frac {x}{\sqrt {x^{2}+y^{2}}}}={\begin{cases}\arctan({\frac {y}{x}})&{\text{if }}x>0,\\\arctan({\frac {y}{x}})+\pi &{\text{if }}x<0{\text{ and }}y\geq 0,\\\arctan({\frac {y}{x}})-\pi &{\text{if }}x<0{\text{ and }}y<0,\\+{\frac {\pi }{2}}&{\text{if }}x=0{\text{ and }}y>0,\\-{\frac {\pi }{2}}&{\text{if }}x=0{\text{ and }}y<0,\\{\text{undefined}}&{\text{if }}x=0{\text{ and }}y=0.\end{cases}}\end{aligned}}}

The inverse tangent denoted in φ = arctan y / x must be suitably defined, taking into account the correct quadrant of (x, y), as done in the equations above. See the article on atan2.

Alternatively, the conversion can be considered as two sequential rectangular to polar conversions: the first in the Cartesian xy plane from (x, y) to (R, φ), where R is the projection of r onto the xy -plane, and the second in the Cartesian zR -plane from (z, R) to (r, θ). The correct quadrants for φ and θ are implied by the correctness of the planar rectangular to polar conversions.

These formulae assume that the two systems have the same origin, that the spherical reference plane is the Cartesian xy plane, that θ is inclination from the z direction, and that the azimuth angles are measured from the Cartesian x axis (so that the y axis has φ = +90°). If θ measures elevation from the reference plane instead of inclination from the zenith the arccos above becomes an arcsin, and the cos θ and sin θ below become switched.

Conversely, the Cartesian coordinates may be retrieved from the spherical coordinates (radius r, inclination θ, azimuth φ), where r ∈, φ ∈ [ 0, 2 π), by x = r sin θ cos φ, y = r sin θ sin φ, z = r cos θ. {\displaystyle {\begin{aligned}x&=r\sin \theta \,\cos \varphi,\\y&=r\sin \theta \,\sin \varphi,\\z&=r\cos \theta.\end{aligned}}}