两个向量之间的夹角公式_计算两个向量之间的夹角

I'm sorry if this question seems a really basic, but I cannot find a good answer online yet.

I'm a little confused with vectors and how to use them in matlab. At the moment I have the following three pair of coordinates (x and y): Person 1, The future location of Person 1 and Person 2. See: The three points in a 2d view

Now I want to calculate the angle between "the vector which goes from person 1 to person 2" and "the vector from person 1 to person 1 future". I've found some matlab functions which could do this with the vectors, but I am not sure I am actually using the right input for each vector.

So now my question is how can I use these coordinates (and the difference between them) to calculate the angle from the image?

解决方案

Although StefanM's solution is a pretty common solution to this, it is actually computationally expensive, but most importantly, incorrect when the vectors are tiny and/or the angle is near 0 or π -- it can actually result in angles that are slightly negative, or slightly exceed π.

Thus, it gives a false sense of robustness.

I'd instead suggest

theta = acos(min(1,max(-1, a(:).' * b(:) / norm(a) / norm(b) )));

More robust, more correct, over 10× faster when run in a loop, and understandable by laymen without documentation, because it still agrees mostly with the "classical" formula.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值