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.
xxxxxxxxxx
1
import math
2
3
4
def calculate_angle(a, b):
5
return math.atan(a / b)
6
7
8
# |\
9
# | \ h - for this function this information is not necessary
10
# a | \
11
# |__*\ <- angle
12
# b
13
14
15
# a, b and h build isosceles right triangle
16
a = 3
17
b = a
18
print(calculate_angle(a, b)) # 0.7853981633974483 <- 45 degrees
19
20
# a, b and h build half of equilateral triangle
21
a = 3
22
b = a * math.sqrt(3)
23
print(calculate_angle(a, b)) # 0.5235987755982987 <- ~30 degrees
Syntax |
xxxxxxxxxx 1 math.atan(number) |
Parameters |
|
Result |
If the value can not be calculated |
Description |
|
xxxxxxxxxx
1
import math
2
3
4
def calculate_angle(a, b):
5
angle = math.atan(a / b)
6
7
return (180 / math.pi) * angle
8
9
10
# |\
11
# | \ h - for this function this information is not necessary
12
# a | \
13
# |__*\ <- angle
14
# b
15
16
17
# a, b and h build isosceles right triangle
18
a = 3
19
b = a
20
print(calculate_angle(a, b)) # 0.7853981633974483 <- 45 degrees
21
22
# a, b and h build half of equilateral triangle
23
a = 3
24
b = a * math.sqrt(3)
25
print(calculate_angle(a, b)) # 0.5235987755982987 <- ~30 degrees