Home > Blockchain >  Find angle from triangle in python (Similar to using sin-1 on scientific calculators)?
Find angle from triangle in python (Similar to using sin-1 on scientific calculators)?

Time:08-31

I want to find the angle from a triangle in Python. I searched other topics here but none of them helped me...

My code:

from math import hypot, sin

opposite = 5
adjacent = 8.66
hypotenuse= hypot(opposite, adjacent)

# Trigonometry - Find angle
sine = opposite / hypotenuse
print(sin(sine))

So, i have a calculator here that have the Sin-1 function, and when i use it in "sine" calc, it returns me the angle 30.

The problem is, i am not finding this sin-1 function on Python. Can someone help me?

Output:

# Whatever this is
0.47943519230195053

Expected output (Which my calculator gives me):

# Angle
30

CodePudding user response:

To get angle, you need arcsin function (sin-1), in Python it is math.asin. Also note that result is in radians, perhaps you want to show degrees:

from math import hypot, asin, degrees

opposite = 5
adjacent = 8.66
hypotenuse= hypot(opposite, adjacent)

# Trigonometry - Find angle
sine = opposite / hypotenuse
rad_angle = asin(sine)
deg_angle = degrees(rad_angle)
print(rad_angle, deg_angle)

>>>0.5236114777699694 30.000727780827372

Also note that having two catheti, you can get angle using atan function (inverse tangent) without hypotenuse calculation

print(degrees(atan(opposite/ adjacent)))
 
  • Related