' '

You can convert from one coordinate system to another using the formulae below.

1. From 2D Cartesian to Polar

\[ \begin{array}{rcl} r & = & \sqrt{x^2 + y^2} \\ \theta & = & \mathrm{atan2}(y, x) \\ \end{array}\]

where atan2 is an arc tangent function which takes into account the quadrant.

2. From Polar to 2D Cartesian

\[ \begin{array}{rcl} x & = & r \cdot \cos(\theta) \\ y & = & r \cdot \sin(\theta) \\ \end{array}\]

3. From 3D Cartesian to Spherical

\[ \begin{array}{rcl} r & = & \sqrt{x^2 + y^2 + z^2} \\ \theta & = & \mathrm{atan2}(z, x) \\ \phi & = & 90^\circ - \arccos(y/r) \\ \end{array}\]

where \(\theta\) corresponds to the azimuth angle and \(\phi\) to the elevation angle.

4. From Spherical to 3D Cartesian

\[ \begin{array}{rcl} x & = & r \cdot \cos\theta \cdot \cos\phi \\ y & = & r \cdot \sin\phi \\ z & = & r \cdot \sin\theta \cdot \cos\phi \\ \end{array}\]

where \(\theta\) corresponds to the azimuth angle and \(\phi\) to the elevation angle.