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

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

问题描述

你如何找到从向量a到b的有符号角度theta?

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

是的,我知道theta = arccos((ab)/(| 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天全站免登陆