Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding tan inverse in python [duplicate]

I'm trying to find the angle made by the line joining a point with the x-axis with the x-axis. So in effect I'm trying to find plain old tan inverse. Here's the code I'm using in Python 3

angle_with_x_axis = math.atan(y_from_centre / x_from_centre)

I'm feeding in the point(1,1) as y_from_centre and x_from_centre and I get

0.7853981633974483

My expected result is 45, but naturally. What am I doing wrong here?

like image 912
Stacker Avatar asked Jan 07 '17 19:01

Stacker


People also ask

How do you find the inverse tangent in Python?

The math. atan() method returns the arc tangent of a number (x) as a numeric value between -PI/2 and PI/2 radians. Arc tangent is also defined as an inverse tangent function of x, where x is the value of the arc tangent is to be calculated.

How do you find the inverse of tan 2?

The value of arctan 2 is 63.435 degrees (or) 1.107 radians. We know that the angle in degrees can be converted into radians by multiplying it by π/180 and the angle in radians can be converted into degrees by multiplying it by 180/π.


1 Answers

math uses radians. For degrees use math.degrees:

>>> math.degrees(math.atan(1))
45.0
like image 176
Uriel Avatar answered Nov 02 '22 11:11

Uriel