【问题标题】:get adjacent and opposite of an triangle with hypotenuse and an angle [closed]获得具有斜边和角度的三角形的相邻和对面[关闭]
【发布时间】:2022-01-10 07:26:26
【问题描述】:

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

【问题讨论】:

  • 不要因为第一次没有得到答案就转发问题。
  • 转发一个不好的问题(这个问题似乎是关于数学,而不是编程)只会更快地到达a question ban

标签: python triangulation


【解决方案1】:

只要记住 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 而不是在度数和弧度之间手动转换。
  • 真的吗?我不知道,我一直在用我的三角老师教我的东西,谢谢你的提示!
【解决方案2】:

我发现最好的方法是:

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 中的数学包允许您使用正弦和余弦,在进行此类触发时将需要它们。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-17
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 2023-01-30
    • 2015-10-15
    • 2023-01-31
    • 1970-01-01
    相关资源
    最近更新 更多