【发布时间】:2022-01-10 07:26:26
【问题描述】:
我正在尝试创建一个程序,使用斜边计算三角形的相邻和对边以及使用 python 的斜边和相邻之间的角度
【问题讨论】:
-
不要因为第一次没有得到答案就转发问题。
-
转发一个不好的问题(这个问题似乎是关于数学,而不是编程)只会更快地到达a question ban。
标签: python triangulation
我正在尝试创建一个程序,使用斜边计算三角形的相邻和对边以及使用 python 的斜边和相邻之间的角度
【问题讨论】:
标签: python triangulation
只要记住 SohCahToa。我们有斜边 (h) 所以相反,我们建立方程 sin(angle) = 相反/斜边。为了找到相反的值,我们将两边乘以斜边得到斜边 * sin(angle) = 相反。用 cos(angle) = 相邻 / 斜边做类似的事情。然后你有你的对立面和相邻面。 就代码而言,它看起来像这样:
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))
【讨论】:
math.radians 而不是在度数和弧度之间手动转换。
我发现最好的方法是:
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 中的数学包允许您使用正弦和余弦,在进行此类触发时将需要它们。
【讨论】: