information:highlighting
Converting between polar and Cartesian coordinates

The polar coordinates r and φ can be converted to the Cartesian coordinates x and y by using the trigonometric functions sine and cosine:

x = r cos φ, y = r sin φ. {\displaystyle {\begin{aligned}x&=r\cos \varphi,\\y&=r\sin \varphi.\end{aligned}}}

The Cartesian coordinates x and y can be converted to polar coordinates r and φ with r ≥ 0 and φ in the interval (− π, π ] by: r = x 2 + y 2 = hypot (x, y) φ = atan2 (y, x), {\displaystyle {\begin{aligned}r&={\sqrt {x^{2}+y^{2}}}=\operatorname {hypot} (x,y)\\\varphi &=\operatorname {atan2} (y,x),\end{aligned}}} where hypot is the Pythagorean sum and atan2 is a common variation on the arctangent function defined as atan2 (y, x) = { 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 \operatorname {atan2} (y,x)={\begin{cases}\arctan \left({\frac {y}{x}}\right)&{\mbox{if }}x>0\\\arctan \left({\frac {y}{x}}\right)+\pi &{\mbox{if }}x<0{\mbox{ and }}y\geq 0\\\arctan \left({\frac {y}{x}}\right)-\pi &{\mbox{if }}x<0{\mbox{ and }}y<0\\{\frac {\pi }{2}}&{\mbox{if }}x=0{\mbox{ and }}y>0\\-{\frac {\pi }{2}}&{\mbox{if }}x=0{\mbox{ and }}y<0\\{\text{undefined}}&{\mbox{if }}x=0{\mbox{ and }}y=0.\end{cases}}}

If r is calculated first as above, then this formula for φ may be stated more simply using the arccosine function: φ = { arccos (x r) if y ≥ 0 and r ≠ 0 − arccos (x r) if y < 0 undefined if r = 0. {\displaystyle \varphi ={\begin{cases}\arccos \left({\frac {x}{r}}\right)&{\mbox{if }}y\geq 0{\mbox{ and }}r\neq 0\\-\arccos \left({\frac {x}{r}}\right)&{\mbox{if }}y<0\\{\text{undefined}}&{\mbox{if }}r=0.\end{cases}}}