# Determine the Transformation from Cylindrical to Rectangular coordinates

In physics is usually defined that in cylindrical coordinates ##\varphi \in [0,2 \pi)##. In relation with Deckart coordinates it is usually written that
$$\varphi=\text{arctg}(\frac{y}{x})$$.
Problem is of course because arctg takes values from ##-\frac{\pi}{2}## to ##\frac{\pi}{2}##. What is the best way to solve this?

#### Attachments

• Marej Spiegel cc.png
51.7 KB · Views: 58
Last edited by a moderator:

jedishrfu
Mentor
To get those ##\phi## values you'd have to have ##x=0## so avoid that condition ie consider it a singular point.

Why do I need to have ##x=0## to get those values of ##\varphi##? I do not understand? I cannot have those values of ##\varphi## with this definition. That is the problem.

mathman
arctan is periodic with period ##\pi##. To get the correct quadrant, use the signs of x and y. y positive is first or second quadrant and x positive is first or fourth quadrant.

pasmith
pasmith
Homework Helper
You can't use arctan(y/x) to uniquely determine $\phi$; both (x,y) and (-x,-y) have the same value of $y/x$ but have $\phi$ values which differ by $\pi$. You must therefore also consider the signs of $x$ and $y$:
$$\phi(x,y) = \begin{cases} \arctan\left (\frac yx\right) & x > 0, y \geq 0 \\ \arctan\left (\frac yx\right) + \pi & x < 0 \\ \arctan\left (\frac yx\right) + 2\pi & x > 0, y < 0 \\ \frac{\pi}{2} & x = 0, y > 0 \\ \frac{3\pi}{2} & x = 0 , y < 0 \\ \mbox{undefined} & x = 0, y = 0 \end{cases}$$

Delta2
Svein
I had the same problem when designing an inexpensive rotary encoder. Since the algorithm had to be implemented in hardware, I used the following algorithm set:$\lvert x \rvert > \lvert y\rvert ? \varphi_{0}=\arctan\frac{\lvert y\rvert}{\lvert x\rvert} :\varphi_{0}=\frac{\pi}{2}-\arctan\frac{\lvert x\rvert}{\lvert y\rvert}$ (sorry for the "C" terminology, but if-then-else looks silly in Tex). From there on it was just a matter of determining the quadrant based on the signs of x and y. And in our case x and y could not be 0 at the same time (but in another case I had to deal with such singularities - and decided not to update anything when passing through a singularity).