EN
Python - math.asin() method example
0 points
The math.asin
function returns number in radians in the range -math.pi/2
to +math.pi/2
. The function calculates the inverted sine function value.
xxxxxxxxxx
1
import math
2
3
4
def calculate_angle(a, h):
5
return math.asin(a / h)
6
7
8
# |\
9
# | \ h
10
# a | \
11
# |__*\ <- angle
12
# b
13
14
15
# a, b and h build an isosceles right triangle
16
a = 3
17
b = a
18
h = math.sqrt(a * a + b * b)
19
print(calculate_angle(a, h)) # 0.7853981633974483 <- 45 degrees
20
21
# a, b and h build half of equilateral triangle
22
a = 3
23
b = a * math.sqrt(3)
24
h = math.sqrt(a * a + b * b)
25
print(calculate_angle(a, h)) # 0.5235987755982987 <- ~30 degrees
26
27
# a, b and h are not able to build triangle
28
a = 3
29
b = a
30
h = 1
31
print(calculate_angle(b, h)) # ValueError
Syntax |
xxxxxxxxxx 1 math.asin(number) |
Parameters |
|
Result |
If the value can not be calculated |
Description |
|
xxxxxxxxxx
1
import math
2
3
4
def calculate_angle(a, h):
5
angle = math.asin(a / h)
6
7
return (180 / math.pi) * angle
8
9
10
# |\
11
# | \ h
12
# a | \
13
# |__*\ <- angle
14
# b
15
16
17
# a, b and h build isosceles right triangle
18
a = 3
19
b = a
20
h = math.sqrt(a * a + b * b)
21
print(calculate_angle(a, h)) # ~45 degrees
22
23
# a, b and h build half of equilateral triangle
24
a = 3
25
b = a * math.sqrt(3)
26
h = math.sqrt(a * a + b * b)
27
print(calculate_angle(a, h)) # ~30 degrees
28
29
# a, b and h are not able to build triangle
30
a = 3
31
b = a
32
h = 1
33
print(calculate_angle(b, h)) # ValueError