10 Replies - 1480 Views - Last Post: 17 March 2013 - 03:56 PM Rate Topic: -----

#1 JeffreyR  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 20-February 13

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

Posted 21 February 2013 - 02:58 AM

Hi i am new on the forum. I am making a smartphone application and this is the first time im 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?
Thank you in Advance.

Here can you see a simple visual representation:
Posted Image

Is This A Good Question/Topic? 0
  • +

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

#2 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 994
  • View blog
  • Posts: 4,158
  • Joined: 14-February 08

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

Posted 21 February 2013 - 03:53 AM

Can you be more specific about what you want this algorithm to do? Are you getting the angle from one point to another?
Was This Post Helpful? 0
  • +
  • -

#3 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: -4
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

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

Posted 21 February 2013 - 08:30 AM

You should know about vectors. These are the primary representations that we use to calculate angles, or more precisely, the relationship and manipulation a of arbitrary points in either 2D or 3D space.

How is you linear algebra?
Was This Post Helpful? 1
  • +
  • -

#4 JeffreyR  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 20-February 13

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

Posted 21 February 2013 - 08:39 AM

View Poststayscrisp, on 21 February 2013 - 03:53 AM, said:

Can you be more specific about what you want this algorithm to do? Are you getting the angle from one point to another?


Okej i'll try a different approach. See new image.

For example in the image if have a coordinate (1.5,2).
From this coordinates i want to calculate angle z.
Numbers on the x and y axis can be positive or negative.


Posted Image

The algorithm:

Input: An x and y value. (For example input (-1.5,5).
Output: angle (z). (105 degrees) (i don't know if this is right just example :P/>)
Was This Post Helpful? 0
  • +
  • -

#5 JeffreyR  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 20-February 13

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

Posted 21 February 2013 - 08:45 AM

View PostButchDean, on 21 February 2013 - 08:30 AM, said:

You should know about vectors. These are the primary representations that we use to calculate angles, or more precisely, the relationship and manipulation a of arbitrary points in either 2D or 3D space.

How is you linear algebra?


You are thinking to difficult ;)/>
Was This Post Helpful? 0
  • +
  • -

#6 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 994
  • View blog
  • Posts: 4,158
  • Joined: 14-February 08

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

Posted 21 February 2013 - 09:12 AM

The function you need is atan2, google it :)/>
Was This Post Helpful? 1
  • +
  • -

#7 JeffreyR  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 20-February 13

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

Posted 22 February 2013 - 01:31 AM

View Poststayscrisp, on 21 February 2013 - 09:12 AM, said:

The function you need is atan2, google it :)/>/>


I know how i can calculate this angle with atan2. I know math :)
I was not asking for a function how to calculate it. I was asking for a algorithm example.
Because i am learning about algorithms.

I have posted this question on 5 diffent forums.
I have gotten few algorithms for calculating this angle.
This helps me understand algorithms.
_____________________________________________________
From johng on mathhelpforum.com
____________________________________________________
double angle(x,y)
d=x*x+y*y
if (d is 0) return error
d=sqrt(d)
v=arccos(x/d)
if (y<0) v=2*pi-v
return v
________________________________________________________
From Mathmom on answer.yahoo.com
_________________________________________________________
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π


If you guys know another algorithm?
The more the better. I want to analyse the difference between them. :smartass:
_________________________________________________________
Was This Post Helpful? 0
  • +
  • -

#8 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: -4
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

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

Posted 22 February 2013 - 12:21 PM

Well, when I suggested linear algebra you said I was overthinking it. Go figure.

How do you intend analyzing these algorithms? They're pretty basic.
Was This Post Helpful? 0
  • +
  • -

#9 JeffreyR  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 20-February 13

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

Posted 17 March 2013 - 07:48 AM

Is it so hard to give direct answer to my question? :online2long:

"No i don't know any algorithms"

I'm doing a application Android application test. I'm testing battery use and speed of algorithms using different sensors.
I have already made 2 algorithms myself and collected 4 algorithms from forums and researchliterature.

So i'm done. Despite the unneccesary discussion, thank you for your time.



View PostButchDean, on 22 February 2013 - 12:21 PM, said:

Well, when I suggested linear algebra you said I was overthinking it. Go figure.

How do you intend analyzing these algorithms? They're pretty basic.

Was This Post Helpful? 0
  • +
  • -

#10 luckielordie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 18-October 11

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

Posted 17 March 2013 - 10:55 AM

Try researching "Complex Conjugate" and Complex numbers. More specifically "Agrand Diagrams". The only info I have is on my unis portal so I can't link you but there should be plenty of other info out there!

Good luck!
Was This Post Helpful? 0
  • +
  • -

#11 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10183
  • View blog
  • Posts: 37,596
  • Joined: 27-December 08

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

Posted 17 March 2013 - 03:56 PM

View PostJeffreyR, on 22 February 2013 - 04:31 AM, said:

From Mathmom on answer.yahoo.com
_________________________________________________________
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π


If you guys know another algorithm?
The more the better. I want to analyse the difference between them. :smartass:
_________________________________________________________

This is the atan2() function.

Quote

Is it so hard to give direct answer to my question? :online2long:

In the context of your question, the math and algorithms are one and the same. An algorithm is just a finite series of steps that return a specific result. As such, the math falls under the scope of an algorithm here. The inverse trig functions return angles, and are defined on restricted domains. You can get the correct values on all the domains by breaking them up piecewise and compensating appropriately. That's how the atan2() function works, as well as your approach with inverse cosine. You could play around with inverse sine in the same way.

You were getting a lot of direct and relevant answers on this.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1