如何从三个点计算角度? [英] How to calculate an angle from three points?
问题描述
假设你有这个:
P1 = (x=2, y=50)
P2 = (x=9, y=40)
P3 = (x=5, y=20)
假设 P1
是圆的中心点.它总是一样的.我想要由 P2
和 P3
组成的角度,或者换句话说,是 P1
旁边的角度.准确地说是内角.它始终是锐角,因此小于 -90 度.
Assume that P1
is the center point of a circle. It is always the same.
I want the angle that is made up by P2
and P3
, or in other words the angle that is next to P1
. The inner angle to be precise. It will always be an acute angle, so less than -90 degrees.
我想:伙计,那是简单的几何数学.但是我现在已经寻找了大约 6 个小时的公式,只发现人们在谈论复杂的 NASA 东西,比如 arccos 和矢量标量产品的东西.我的头感觉就像在冰箱里.
I thought: Man, that's simple geometry math. But I have looked for a formula for around 6 hours now, and only find people talking about complicated NASA stuff like arccos and vector scalar product stuff. My head feels like it's in a fridge.
这里有一些数学大师认为这是一个简单的问题?我认为编程语言在这里并不重要,但对于那些认为重要的人来说:java 和objective-c.我两个都需要它,但还没有为这些标记它.
Some math gurus here that think this is a simple problem? I don't think the programming language matters here, but for those who think it does: java and objective-c. I need it for both, but haven't tagged it for these.
推荐答案
如果你的意思是P1是顶点的角度那么使用余弦定律 应该起作用:
If you mean the angle that P1 is the vertex of then using the Law of Cosines should work:
arccos((P122+ P132 - P232)/(2 *P12 * P13))
arccos((P122 + P132 - P232) / (2 * P12 * P13))
其中 P12 是从 P1 到 P2 的段的长度,计算公式为
where P12 is the length of the segment from P1 to P2, calculated by
sqrt((P1x -P2x)2 +(P1y -P2y)2)
sqrt((P1x - P2x)2 + (P1y - P2y)2)
这篇关于如何从三个点计算角度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!