How to solve atan2 function Problem?

There is a problem with atan2. when the value reaches pi, the output returns to zero, While I would like to see the angles more than pi to infinity. How can I solve this? Thanks

4 Kommentare

Azzi Abdelmalek
Azzi Abdelmalek am 4 Jan. 2014
What do you mean? give an example
Javad
Javad am 4 Jan. 2014
Bearbeitet: Javad am 4 Jan. 2014
Thanks to all, In my simulation the angles is changing from zero to more than 360 deg. due to the definition of atan2 and what you said, atan2 only outputs the angles between [-180,180]. I could make the code so that displays the result from zero to 360 deg by adding 2*pi to the answer(whit respect to quarters X & Y sign).
a=atan2(y,x); if y<0 && x<0 a=a+2*pi; elseif y<0 && x>0 a=a+2*pi; end
so I got my answer so far. after 360 the answer comebacks to the zero and start again. do you think if there is a way so that the display goes more than 360.
Let's look at the tangent of 60 and every 360 after that (for a while):
angles = 60:360:4000
tangents = tand(angles);
fprintf('%.3f', tangents);
now look at what it reports:
angles =
60 420 780 1140 1500 1860 2220 2580 2940 3300 3660
1.7321.7321.7321.7321.7321.7321.7321.7321.7321.7321.732
Now, if you were to take one of those numbers, say the 3rd 1.7321 number, how is the arctangent function supposed to know that it came from an angle of 780 , and not from 60, 420, or any of an infinite number of other possibilities that you passed it? Please tell me how the atand function should know.
Javad
Javad am 4 Jan. 2014
Bearbeitet: Javad am 4 Jan. 2014
that's right. Of course By the code I wrote above, display (not the result of atan2) has a range of 0 to 360 deg. however it disable displaying the negative angle.

Melden Sie sich an, um zu kommentieren.

Antworten (3)

Roger Stafford
Roger Stafford am 4 Jan. 2014

2 Stimmen

It looks as though you need the 'unwrap' function:
http://www.mathworks.com/help/matlab/ref/unwrap.html
It depends on making adjustments to a sequence of angles which don't change by more than pi radians from one to the next. The function 'atan2' itself is limited to a range from -pi to +pi, though you can use the 'mod' function to adjust it to some other range which spans 2*pi, but there is no way of spanning more a 2*pi range without additional information beyond simply a pair of cartesian coordinates.
Mischa Kim
Mischa Kim am 4 Jan. 2014
Bearbeitet: Mischa Kim am 4 Jan. 2014

1 Stimme

To make atan2 a proper, one-to-one (called bijective) function it -- by definition -- returns angular values between -pi and +pi. In other words, there is no solution to your problem, in general.
However, if you do have more information on your problem there might be ways to back out angular values greater than -pi and +pi.
Azzi Abdelmalek
Azzi Abdelmalek am 4 Jan. 2014
Bearbeitet: Azzi Abdelmalek am 4 Jan. 2014

0 Stimmen

What you are doing is not clear. But if you want to have angles more than pi, you have to add k*pi to the result given by atan2 which is in the interval [-pi pi]. The k depends on what you are doing.
The informations Y and X given to atan2 do not allow to know if the result is alpha or alpha+k*pi

2 Kommentare

Greg Heath
Greg Heath am 4 Jan. 2014
Do you mean alpha +/- 2*k*pi?
Azzi Abdelmalek
Azzi Abdelmalek am 4 Jan. 2014
Bearbeitet: Azzi Abdelmalek am 4 Jan. 2014
No, I mean alpha+k*pi ( k is a positive or negative integer)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Programming finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 4 Jan. 2014

Bearbeitet:

am 4 Jan. 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by