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.
import math
def calculate_angle(a, h):
return math.asin(a / h)
# |\
# | \ h
# a | \
# |__*\ <- angle
# b
# a, b and h build an isosceles right triangle
a = 3
b = a
h = math.sqrt(a * a + b * b)
print(calculate_angle(a, h)) # 0.7853981633974483 <- 45 degrees
# a, b and h build half of equilateral triangle
a = 3
b = a * math.sqrt(3)
h = math.sqrt(a * a + b * b)
print(calculate_angle(a, h)) # 0.5235987755982987 <- ~30 degrees
# a, b and h are not able to build triangle
a = 3
b = a
h = 1
print(calculate_angle(b, h)) # ValueError
1. Documentation
Syntax |
|
Parameters |
|
Result |
If the value can not be calculated |
Description |
|
2. Working with degrees
import math
def calculate_angle(a, h):
angle = math.asin(a / h)
return (180 / math.pi) * angle
# |\
# | \ h
# a | \
# |__*\ <- angle
# b
# a, b and h build isosceles right triangle
a = 3
b = a
h = math.sqrt(a * a + b * b)
print(calculate_angle(a, h)) # ~45 degrees
# a, b and h build half of equilateral triangle
a = 3
b = a * math.sqrt(3)
h = math.sqrt(a * a + b * b)
print(calculate_angle(a, h)) # ~30 degrees
# a, b and h are not able to build triangle
a = 3
b = a
h = 1
print(calculate_angle(b, h)) # ValueError