两条线之间的角度从同一点开始

发布于 2024-09-16 22:46:36 字数 204 浏览 2 评论 0原文

假设我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦亿 2024-09-23 22:46:36

找到中心和两点之间的增量向量

d1 = p1-c;
d2 = p2-c;

您可以使用 atan2 来获取每个点的角度:

angle1 = atan2(d1.Y, d1.X)
angle2 = atan2(d2.Y, d2.X)

并且您想要的角度只是差异:

a = angle2-angle1;

取决于您是否希望将角度表示为 0 到 2pi 之间,或者-2pi 和 0,您可以使用 while 循环不断减去 2pi / 添加 2pi 以获得您想要的表示,尽管您只需要在向人类呈现角度时执行此操作

Find the delta vectors between the center and your two points

d1 = p1-c;
d2 = p2-c;

You can use atan2 to get the angle of each of these:

angle1 = atan2(d1.Y, d1.X)
angle2 = atan2(d2.Y, d2.X)

and your desired angle is simply the difference:

a = angle2-angle1;

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

梦在夏天 2024-09-23 22:46:36

将点转换为向量(从每个端点减去中心点)并使用点积来计算角度。

Convert the points to vectors (subtract the center point from each end point) and use the dot product to compute the angle.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文