Python Math atan2() Method
Python Math atan2() returns the arctangent of the given X and Y coordinate values.
Python Math atan2() Syntax
Here is the syntax of the atan2() method:
import math
math.atan2(y, x)
Note: atan2() is not directly accessible, you need to import the math module and then call the method via the math static object.
Python Math atan2() Parameters
- x : A value.
- y : a value.
Python Math atan2() Return Value
Returns the arctangent of the given X and Y coordinate values.
Python Math atan2() Example#1
The following shows an example of using the atan2() method.
#!/usr/bin/python3
import math
print ("atan2(-0.50,-0.50) : ", math.atan2(-0.50,-0.50))
print ("atan2(0.50,0.50) : ", math.atan2(0.50,0.50))
print ("atan2(50,50) : ", math.atan2(50,50))
print ("atan2(-100,100) : ", math.atan2(-100,100))
print ("atan2(100,200) : ", math.atan2(100,200))
Output:
Python Math atan2() Example#2
When an integer value is passed, it returns a TypeError.
#!/usr/bin/python3
import math
y, x = 3, 6
theta = math.atan2([y], [x])
print(theta)
Output: