计算围绕点执行的旋转
我在 2D 空间中有两个点,以原点 (0,0) 为中心。第一个点代表起始位置,第二个点代表结束位置。我需要计算两点之间的旋转角度,我的问题是每个点到 (0,0) 的斜边不相等。
有人可以告诉我如何计算出两点之间的角度,请记住它们可能位于相对于 (0,0) 的任何位置。
非常感谢,
马特。
I have two points in 2D space, centred on origin (0,0). The first point represents the starting location and the second represents the end location. I need to calculate the angle of rotation between the two points, my problem being that the hypoteneuse from each point to (0,0) is not equal.
Could someone tell me how to work out the angle between the two points, bearing in mind that they could be anywhere relative to (0,0).
Many thanks,
Matt.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设点 1 为 (x1,y1),点 2 为 (x2,y2)
从 X 轴到点 1 的角度相对于 (0,0) 的正切为 y1/x1
从 X 轴角度的正切到点 2,相对于 (0,0) 的是 y2/x2
取反正切(这是正确的术语吗?计算器上的 Tan-1)以获得每个点的实际角度,然后减去以获得您想要的答案寻找
Let's say point 1 is (x1,y1) and point 2 is (x2,y2)
The tangent of the Angle from X axis to point 1, relative to (0,0) is y1/x1
The tangent of the Angle from X axis to point 2, relative to (0,0) is y2/x2
Take the arc tangent (is that the right term? Tan-1 on a calculator) to get the actual angle for each, then subtract to get the answer you're looking for
通过取标准化内积的反余弦可以轻松实现这一点两个向量。也就是说,给定 u = (ux, uy) 和 v = (vx , vy),两者之间的角度由 θ = acos(u·v/| 给出u||v|),其中 u · v = uxv x + uyvy 是两者的点积,| |运算符是 |u| 给出的 l2 法线= sqrt(ux2 + uy2)。这将导致可应用于其中一个向量的最小旋转,从而使它们成为彼此的线性倍数。因此,如果您想从一个方向开始,您可能需要摆弄 θ 的符号,以确保您朝着正确的方向前进。
This is easily accomplished taking the arccosine of the normalized inner product of the two vectors. That is, given u = (ux, uy) and v = (vx, vy), the angle between the two is given by θ = acos(u·v/|u||v|), where u · v = uxvx + uyvy is the dot product of the two and the | | operator is the l2 normal given by |u| = sqrt(ux2 + uy2). This will result in the smallest rotation that can be applied to one of the vectors that will make them linear multiples of each other. Therefore, you may need to fiddle with the sign of θ to make sure you're going in the right direction if you have one you want to start from.