Jump to content

Algorithms that convert x and y value to an angle (degrees or radian.


JeffreyR

Recommended Posts

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 a angle. The angle can be 0-360 degrees or 0-2π radians.

 

 

Does anyoneknow 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?

 

Below is a visual presentation of the conversion the algorithm has to do:

 

34g6g3m.jpg

 

 

Thank you in Advance!

Link to comment
Share on other sites

Inverse tangent.

 

You just need to take care to adjust the result for the fact that [imath]\arctan(y/x)[/imath] and [imath]\arctan(-y/-x)[/imath] yield the same answer. Many calculators and computers do this adjustment for you in a function typically called atan2. http://en.wikipedia.org/wiki/Atan2

Edited by D H
Link to comment
Share on other sites

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 a angle. The angle can be 0-360 degrees or 0-2π radians.

 

 

 

Does anyoneknow 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?

 

Below is a visual presentation of the conversion the algorithm has to do:

 

34g6g3m.jpg

 

 

Thank you in Advance!

Inverse tangent.

 

You just need to take care to adjust the result for the fact that [imath]\arctan(y/x)[/imath] and [imath]\arctan(-y/-x)[/imath] yield the same answer. Many calculators and computers do this adjustment for you in a function typically called atan2. http://en.wikipedia.org/wiki/Atan2

That's exactly what I was going to say. I'm just bumping the thread with a quote of the OP so that the OP gets a notification that their question is answered.
Link to comment
Share on other sites

There I suggested an alternative algorithm on complex numbers to obtain the same kind of result as atan2():

http://www.scienceforums.net/topic/69084-suggest-a-topic-for-master-thesis/#entry711886

beware I haven't tested it. While I've an excellent feeling that it works, whether the computing time and accuracy are interersting remains to be seen.

 

And anyway, your purpose may not be to program an numerical algorithm if Atan2() is available!

Link to comment
Share on other sites

I did not know that. Thats very interesing i will look into that! smile.png



Sorry this is complex for me.

I am not on this level yet. I will certainly look into it if i get to this level.

Thank you for you help.

 

The post above was for "D H"

 

There I suggested an alternative algorithm on complex numbers to obtain the same kind of result as atan2():

http://www.scienceforums.net/topic/69084-suggest-a-topic-for-master-thesis/#entry711886

beware I haven't tested it. While I've an excellent feeling that it works, whether the computing time and accuracy are interersting remains to be seen.

 

And anyway, your purpose may not be to program an numerical algorithm if Atan2() is available!

Link to comment
Share on other sites

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 a angle. The angle can be 0-360 degrees or 0-2π radians.

 

 

Does anyoneknow 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?

 

Below is a visual presentation of the conversion the algorithm has to do:

 

34g6g3m.jpg

 

 

Thank you in Advance!

 

Hi, Jeffrey. Another poster touched on it, but I'll try to expound a little bit because you said this area of math is a bit above your level of understanding.

 

1.) So first thing is first: we need to collect the points from (I'm assuming) a user.

 

2.) Then we'd set up an equation. Let N = angle

 

Tan N = y/x

 

3.) Solve for N

 

N = Tan -1* (y/x)

 

* "Tan -1" is supposed to read "inverse tangent of" but I'm unsure of how to notate it on a keyboard.

 

4.) Evaluate above equation.

 

Example: user puts in (1, 1).

 

Tan N = 1/1

 

N = Tan-1 (1/1)

 

N = 45 (degrees).

 

Hope this helps.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.