Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python atan or atan2, what should I use?

Tags:

python

math

My formula f=arctan(ImZ/ReZ)

There are two options:

Option 1 (atan):

ImZ=-4.593172163003 ImR=-4.297336384845  >>> z=y/x >>> f1=math.atan(z) >>> f1 0.8186613519278327 

Option 2 (atan2)

>>> f=math.atan2(y,x) >>> f -2.3229313016619604 

Why are these two results different?

like image 319
Richard Rublev Avatar asked Mar 02 '16 13:03

Richard Rublev


People also ask

Should I use atan or atan2?

atan is used if we only know or are interested in y/x not y and x individually. So if p = y/x then to get α we'd use atan(p) . You cannot use atan2 to determine the quadrant, you can use atan2 only if you already know which quadrant your in!

What is the difference between atan and atan2 in Python?

The atan2() function, as its name suggests, is utilized to calculate and return the value of the arc tangent of y/x in terms of radians in Python. The atan() function has the same math library functions with atan2() .

When use atan vs atan2 Matlab?

The four-quadrant inverse tangent, atan2(Y,X) , returns values in the closed interval [-pi,pi] based on the values of Y and X , as shown in the graphic. In contrast, atan(Y/X) returns results that are limited to the interval [-pi/2,pi/2] , shown on the right side of the diagram.

Is atan2 slow?

It's because atan2, along with all the other inverse trigonometric functions, is incredibly slow.


1 Answers

Atan takes single argument and Atan2 takes two arguments.The purpose of using two arguments instead of one is to gather information on the signs of the inputs in order to return the appropriate quadrant of the computed angle, which is not possible for the single-argument Atan

atan2 results for each x,y

Atan2 result is always between -pi and pi.

Reference: https://en.wikipedia.org/wiki/Atan2

like image 83
Abdul Rauf Avatar answered Sep 24 '22 18:09

Abdul Rauf