从 A 指向 B 的向量的角度

发布于 2024-09-20 00:41:46 字数 195 浏览 2 评论 0原文

我的数学不是最好的,但对于我现在所做的,我需要计算向量的角度,如下图箭头所示:

alt text

我在 2D 平面上有一个点 A 和一个点 B。我需要计算以下内容:

  • 箭头必须旋转才能指向 B 的角度

I'm not the best in Maths, but for what I am doing now I need to calculate the angle of the vector which is shown as arrow in the picture below:

alt text

I have a point A and a point B in a 2D plane. I need to calculate the following:

  • The angle in which the arrow must be rotated in order to point to B

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

拍不死你 2024-09-27 00:41:53

arctan((Ay - By) / (Ax - Bx)) 并注意 Ax = Bx 的特殊情况

arctan((A.y - B.y) / (A.x - B.x)) and note the special case where A.x = B.x

再见回来 2024-09-27 00:41:51

atan2(yB-yA, xB-xA),假设您的库有 atan2。否则,您需要使用 atan,如果 B 在 A 的右侧,它将返回正确的答案,否则将返回 180 度。另请注意,返回值以弧度为单位,如有必要,您可以通过乘以 180/pi 将弧度转换为度数。

维基百科有关于几何形状的详细解释。

atan2(yB-yA, xB-xA), assuming your library has atan2. Otherwise you need to use atan, which will return the correct answer if B is to the right of A, and will be 180 degrees off otherwise. Also note that the return value is in radians, you can convert radians to degrees by multiplying by 180/pi if necessary.

Wikipedia has a detailed explanation of the geometry.

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