获得具有斜边和角度的三角形的相邻和相反

get adjacent and opposite of an triangle with hypotenuse and an angle

我正在尝试创建一个程序,使用斜边计算三角形的邻边和对边,以及斜边和邻边之间的角度 python

记住SohCahToa。我们有斜边 (h) 因此相反,我们建立方程 sin(angle) = opposite/hypotenuse。为了找到对数,我们将两边乘以斜边得到斜边 * sin(angle) = opposite。用 cos(angle) = adjacent / hypotenuse 做类似的事情。然后你有你的对立面和相邻面。 就代码而言,它看起来像这样:

import math # we need this specifically to use trig functions
angle = (some angle here)
hypotenuse = (some number here)
opposite = hypotenuse * math.sin(math.radians(angle))
# we have to multiply the angle by PI/180 because the python sin function uses radians and we do this by using math.radians() is how to convert from degrees to radians.
adjacent = hypotenuse * math.cos(angle * (math.pi/180))

我发现的最佳方法是:

import math
hype = 10
angle = 30
adj = 0
opp = 0
adj = hype*math.cos(math.radians(angle))
opp = hype*math.sin(math.radians(angle))
opp
print(str(opp) + ' is the opposite side value')
print(str(adj) + ' is the adjacent side value')
print(str(hype) + ' is the hypotenuse')
print(str(angle) + ' is the angle')

python 中的数学包允许您使用正弦和余弦,在像这样进行三角运算时您将需要它们。