Python math.atan2() Method

Python math 模块Python math Module

Python math.atan2(y,x)Returns the arctangent of the given y and x coordinate values, atan(y / x), in radians, with the result between -pi and pi.

Python Version: 1.4

Syntax

The syntax of the math.atan2() method is as follows:

math.atan2(y, x)

Parameter description:

  • xy -- Required, a positive or negative number.
  • yx -- Required, a positive or negative number.

Return Value

Returns a floating-point number representing the arctangent of the y and x coordinate values, with the result between -pi and pi.

Example

The following example returns the arctangent of y/x:

Example

# Import the math package
import math

# Output the arctangent of y/x
print(math.atan2(8, 5))
print(math.atan2(20, 10))
print(math.atan2(34, -7))

Output:

1.0121970114513341
1.1071487177940904
1.7738415440483617

Python math 模块Python math Module

Other Extensions