Convert Between Rectangular And Polar Coordinates

Polar to Rectangular: $$ \begin{align*} x& = r \sin \theta \cos \varphi \\ y& = r \sin \theta \sin \varphi \\ z& = r \cos \theta \\ \end{align*} $$ Rectangular to Polar: $$ \begin{align*} r& = \sqrt{x^2 + y^2 + z^2} \\ \cos \theta& = \frac{z}{r} \\ \cos \varphi& = \frac{x}{\sqrt{x^2 + y^2}} \\ \sin \varphi& = \frac{y}{\sqrt{x^2 + y^2}} \\ \tan \varphi& = \frac{y}{x} \\ \end{align*} $$