本文介绍了计算两个角度之间的绝对差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个角度a和b,我想计算两个角度之间的绝对差.例子
I have two angles a and b, I want to calculate the absolute difference between both angles. Examples
>> absDiffDeg(360,5)
ans = 5
>> absDiffDeg(-5,5)
ans = 10
>> absDiffDeg(5,-5)
ans = 10
推荐答案
归一化差异,由于mod(x,y)采用y的符号,因此不需要进行abs操作.
Normalize the difference, abs operation is not necessary because mod(x,y) takes the sign of y.
normDeg = mod(a-b,360);
这将是一个介于0-360之间的数字,但是我们希望最小的角度介于0-180之间.最简单的方法是
This will be a number between 0-360, but we want the smallest angle which is between 0-180. Easiest way to get this is
absDiffDeg = min(360-normDeg, normDeg);
这篇关于计算两个角度之间的绝对差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!