寻找向量之间的有符号角 [英] Finding Signed Angle Between Vectors

查看:19
本文介绍了寻找向量之间的有符号角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何求向量 a 到 b 的带符号角 theta?

How would you find the signed angle theta from vector a to b?

是的,我知道 theta = arccos((a.b)/(|a||b|)).

And yes, I know that theta = arccos((a.b)/(|a||b|)).

但是,这不包含符号(即它不区分顺时针或逆时针旋转).

However, this does not contain a sign (i.e. it doesn't distinguish between a clockwise or counterclockwise rotation).

我需要一些可以告诉我从 a 旋转到 b 的最小角度的东西.正号表示从 +x 轴向 +y 轴旋转.相反,负号表示从 +x 轴向 -y 轴旋转.

I need something that can tell me the minimum angle to rotate from a to b. A positive sign indicates a rotation from +x-axis towards +y-axis. Conversely, a negative sign indicates a rotation from +x-axis towards -y-axis.

assert angle((1,0),(0,1)) == pi/2.
assert angle((0,1),(1,0)) == -pi/2.

推荐答案

如果您选择的数学库中有 atan2() 函数:

If you have an atan2() function in your math library of choice:

signed_angle = atan2(b.y,b.x) - atan2(a.y,a.x)

这篇关于寻找向量之间的有符号角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆