EN
Python - math.atan() method example
0
points
The math.atan
function returns number in radians in the range -math.pi/2
to +math.pi/2
. The function calculates the inverted tangent function value.
import math
def calculate_angle(a, b):
return math.atan(a / b)
# |\
# | \ h - for this function this information is not necessary
# a | \
# |__*\ <- angle
# b
# a, b and h build isosceles right triangle
a = 3
b = a
print(calculate_angle(a, b)) # 0.7853981633974483 <- 45 degrees
# a, b and h build half of equilateral triangle
a = 3
b = a * math.sqrt(3)
print(calculate_angle(a, b)) # 0.5235987755982987 <- ~30 degrees
1. Documentation
Syntax |
|
Parameters |
|
Result |
If the value can not be calculated |
Description |
|
2. Working with degrees
import math
def calculate_angle(a, b):
angle = math.atan(a / b)
return (180 / math.pi) * angle
# |\
# | \ h - for this function this information is not necessary
# a | \
# |__*\ <- angle
# b
# a, b and h build isosceles right triangle
a = 3
b = a
print(calculate_angle(a, b)) # 0.7853981633974483 <- 45 degrees
# a, b and h build half of equilateral triangle
a = 3
b = a * math.sqrt(3)
print(calculate_angle(a, b)) # 0.5235987755982987 <- ~30 degrees