# Algorithms: x,y values convert to angle.

#### JeffreyR

Hi i am new on the forum. I am making a smartphone application and this is the first time i’m working with algorithms.
I am looking for algorithms that can convert x and y value on a Cartesian plane (x,y) to an angle. The angle can be 0-360 degrees or 0-2? radian.

Does anyone know of such algorithms?
I have looked for geometric algorithms on Google. I have also found a list of algorithms on Wikipedia, but no luck finding this particular algorithm.
Also are there search databases that solely contain algorithms?

http://tinypic.com/view.php?pic=34g6g3m&s=6

#### MarkFL

You could use a few conditional statements to determine which quadrant the point is in, determine its distance $$\displaystyle r$$ from the origin, and then use the relations:

$$\displaystyle x=r\cos(\theta)$$

$$\displaystyle y=r\sin(\theta)$$

to determine the angle $$\displaystyle \theta$$.

If you need further help, I will check back tomorrow (as it is very late here now), and help you develop the algorithm you need, unless someone else chimes in.

#### JeffreyR

Thank you
And i understand. I live in holland, here it is still day :wink:

I have also posted this question on yahoo and got 1 algorithm:
________________________________________________________________
Q1: If x > 0, y > 0 ----> ? = arctan(y/x)
Q2: If x < 0, y > 0 ----> ? = arctan(y/x) + 180° or arctan(y/x) + ?
Q3: If x < 0, y < 0 ----> ? = arctan(y/x) + 180° or arctan(y/x) + ?
Q4: If x > 0, y < 0 ----> ? = arctan(y/x) + 360° or arctan(y/x) + 2?
____________________________________________________________
I think this are the additional statements you were referring to.

If understand correctly your method is different.
This is good because, it would be ideal for my research to implement multiple algorithms into my application.
It also give insight in how algorithms can differ.

#### JeffreyR

Thank you both for your answer. Now i'm exited. I'm curious wich algorithm wil be fastest