两条线之间的角度从同一点开始
假设我是 2d 平面上的任意两点 (p1(x1,y1), p2(x2,y1)),并且这两个点与中心 (c(c1,c2)) 形成一条线。因此我是两条线在同一点结束。我想知道如何计算这两条线之间的角度。我希望能够显示 0-2pi 的角度范围。还有 0-(-2pi),它让 p1 和 c 形成的线成为线 1 和其他线 2。 我确实通过使用 atan2() 有一些想法,但没有像我想要的那样工作。 谢谢
Lets say I am any two points on 2d plane (p1(x1,y1), p2(x2,y1)) and both points forms a line with the center(c(c1,c2)). Therefore I am two lines end at same point. I want to know how can I calculate angle between those two lines. I want to be able to show angle range from 0-2pi. Also 0-(-2pi) which let the line form by p1 and c to be line 1 and other line 2.
I do have some idea by using atan2() but did not work out like I want it to.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
找到中心和两点之间的增量向量
您可以使用 atan2 来获取每个点的角度:
并且您想要的角度只是差异:
取决于您是否希望将角度表示为 0 到 2pi 之间,或者-2pi 和 0,您可以使用 while 循环不断减去 2pi / 添加 2pi 以获得您想要的表示,尽管您只需要在向人类呈现角度时执行此操作
Find the delta vectors between the center and your two points
You can use atan2 to get the angle of each of these:
and your desired angle is simply the difference:
Depending on whether you want the angle to be represented as between 0 and 2pi, or -2pi and 0, you can just use a while loop to keep subtracting 2pi / adding 2pi to get the representation you want, although you should only need to do this when presenting the angle to a human
将点转换为向量(从每个端点减去中心点)并使用点积来计算角度。
Convert the points to vectors (subtract the center point from each end point) and use the dot product to compute the angle.