Results 1 to 3 of 3

Math Help - Algorithms: x,y values convert to angle.

  1. #1
    Newbie
    Joined
    Feb 2013
    From
    Drenthe
    Posts
    2

    Question Algorithms: x,y values convert to angle.

    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 ofalgorithms 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:





    Thank you in Advance!
    Follow Math Help Forum on Facebook and Google+

  2. #2
    MHF Contributor

    Joined
    Apr 2005
    Posts
    15,361
    Thanks
    1311

    Re: Algorithms: x,y values convert to angle.

    Convert the point (x, y) to what angle? Do you mean the angle the line through (0, 0) and (x, y) makes with the x-axis? That appears to be what your pictures show. If so then you need to look at the right triangle which has vertices at (0, 0), (x, y), and (x, 0). That has its right angle at (x, 0) and has tan(\theta)= y/x so that \theta= arctan(y/x)= tan^{-1}(y/x). One complication is that, since the tangent function is NOT one to one, the arctangent is defined only for -\pi/2\le \theta\le \pi/2. So, if you want [itex]\theta[/itex] from 0 to 360 degrees, you will need an algorithm like

    If x= 0, if y>0 \theta= 90 else \theta= 270 (to avoid dividing by 0)
    else, A= arctan(y/x) {If If A>0 and then \theta= A else \theta= 360+ A}
    else ( x\le 0 now) if A> 0, \theta= 90+ A else \theta= 270- A
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Super Member
    Joined
    Dec 2012
    From
    Athens, OH, USA
    Posts
    611
    Thanks
    248

    Re: Algorithms: x,y values convert to angle.

    Here's psuedo code for an algorithm that I have used successfully. It assumes the existence of an arccos function that returns a value in [0,pi]

    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
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Algorithms: x,y values convert to angle.
    Posted in the Differential Geometry Forum
    Replies: 1
    Last Post: February 27th 2013, 08:43 AM
  2. Convert range of values to no linear range
    Posted in the Calculus Forum
    Replies: 1
    Last Post: December 21st 2012, 09:09 AM
  3. Convert Angle measure to Degrees Minutes Seconds
    Posted in the Trigonometry Forum
    Replies: 3
    Last Post: September 15th 2010, 03:58 PM
  4. two different values for angle A ?
    Posted in the Trigonometry Forum
    Replies: 1
    Last Post: May 20th 2010, 10:55 PM
  5. How do you convert an angle to a fraction?
    Posted in the Geometry Forum
    Replies: 6
    Last Post: September 2nd 2009, 05:02 PM

Search Tags


/mathhelpforum @mathhelpforum