Changing the atan2 function so that it ranges from 0 to 4*pi

16 Ansichten (letzte 30 Tage)
대수 박
대수 박 am 15 Feb. 2023
Bearbeitet: John D'Errico am 16 Feb. 2023
I know that the matlab atan function returns values in the range of -pi/2 to pi/2. How do i change it so that it goes over the full range 0 to 4*pi?
t=atan2(path_y,path_x);

Antworten (1)

John D'Errico
John D'Errico am 15 Feb. 2023
Bearbeitet: John D'Errico am 15 Feb. 2023
Why do you think that the full range is 4*pi? It is not. There are 2*pi radians (360 degrees) in a circle. 4*pi radians is TWO full revolutions, so impossible to give a unique result that ranges over the interval you asked about.
Can atan itself, using only ONE argument be changed, so it works like atan2? NO. That is also impossible. There is insufficient information to do so.
You already have atan2. In fact, you even clearly know about atan2. But atan2 cannot be changed to return a unique and valid output on the range [0,4*pi], any more than atan, based on only the one piece of information, can be changed to extend its output over an extended interval of length 2*pi.
  2 Kommentare
대수 박
대수 박 am 16 Feb. 2023
I try to represent the following trajectory in a polar coordinate system.
However, the range of theta exceeds 360 degrees, so the value of atan2 output is not properly.
John D'Errico
John D'Errico am 16 Feb. 2023
Bearbeitet: John D'Errico am 16 Feb. 2023
Why is that even remotely a problem that uses atan2? Or atan for that matter? What you show is a classical Archimedian spiral. The equations are well defined, with a radius that increases linearly with polar angle.
theta = linspace(0,4*pi);
r = theta*5/(4*pi);
x = r.*cos(theta);
y = r.*sin(theta);
plot(x,y)
axis equal
Theta can go out as far as you wish to generate a longer spiral. All you need is for sin and cos to be periodic functions, and as I recall, they are exactly that. For example:
theta = linspace(0,12*pi,1000);
r = theta*5/(4*pi);
x = r.*cos(theta);
y = r.*sin(theta);
plot(x,y)
axis equal
The second plot went all the way out to 12*pi. At no place in the computation did I need to relay on atan, or atan2 for that matter.
My statement still stands. atan and atan2 have their given ranges, and they are well defined with those ranges. There is no need to have more, nor would it make sense.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by