计算三个点的角度

huangapple go评论151阅读模式
英文:

Computing the angle of three points

问题

我有三个点,每个点都有一个 Bar_Index 和 Value

我试图计算三个点之间的角度,以使点 C 是中心的一个(在图中的顶部),而 12 是两侧的点(点C的左侧和右侧)。

我不确定为什么我的计算出的角度如此小,根据图示,它应该要大得多(大于20度)。有人知道我漏掉了什么吗?

这是代码,

Cx = bar_index_0
Cy = Value_0

P0x = bar_index_1
P0y = Value_1

P1x = bar_index_2
P1y = Value_2

P0C = math.sqrt(math.pow((P0x-Cx),2)+math.pow((P0y-Cy),2))
P1C = math.sqrt(math.pow((P1x-Cx),2)+math.pow((P1y-Cy),2))
P0P1 = math.sqrt(math.pow((P1x-P0x),2)+math.pow((P1y-P0y),2))

top = (P1C*P1C + P0C*P0C - P0P1*P0P1)
down = 2*P1C*P0C
Angle = (math.todegrees(math.acos(top/down)))

此外,如果有人对计算三角形内的三个角有更好的建议,我将很高兴听到它。

英文:

I have three points, each point has a Bar_Index and Value.
I am trying to compute the angle between the tree points in a way that point C is the one in the center (on the top in the fig) and 1 and 2 are the ones on the sides (left and right of point C).
I am not sure why my computed angle in degree is so small, based on the figure it should be much larger (more than 20 degree).Does anyone know what I am missing?
Here is the code,


Cx = bar_index_0
Cy = Value_0

P0x = bar_index_1
P0y = Value_1

P1x = bar_index_2
P1y = Value_2

P0C = math.sqrt(math.pow((P0x-Cx),2)+math.pow((P0y-Cy),2))
P1C = math.sqrt(math.pow((P1x-Cx),2)+math.pow((P1y-Cy),2))
P0P1 = math.sqrt(math.pow((P1x-P0x),2)+math.pow((P1y-P0y),2))

top = (P1C*P1C + P0C*P0C - P0P1*P0P1)
down = 2*P1C*P0C
Angle = (math.todegrees(math.acos(top/down)))

Also, if anyone has a better suggestion to compute the three angles inside the triangle I will be happy to hear it.

计算三个点的角度

计算三个点的角度
计算三个点的角度

答案1

得分: 1

在向量数学中,角度是((p0-C)点乘(p1-C)) / (len(p0-C)*len(p1-C))。
因此,尝试:

P0Cx = P0x - Cx
P0Cy = P0y - Cy
P1Cx = P1x - Cx
P1Cy = P1y - Cy
dot = P0Cx * P1Cx + P0Cy * P1Cy
div = P0C * P1C
angle = math.acos(dot / div)
英文:

In vector math, the angle is ((p0-C) dot (p1-C)) / (len(p0-C)*len(p1-C)).
So, try:

P0Cx = P0x-Cx
P0Cy = P0y-Cy
P1Cx = P1x-Cx
P1Cy = P1y-Cy
dot = P0Cx*p1Cx + P0Cy*P1Cy
div = P0C*P1C
angle = math.acos(dot/div)

huangapple
  • 本文由 发表于 2023年3月7日 12:17:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/75658011.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定