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
Normalize the difference, abs operation is not necessary because mod(x,y) takes the sign of y.
normDeg = mod(a-b,360);
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);
How about unsing unwrap ? Here is a try:
absDiffDeg = @(a,b) abs(diff(unwrap([a,b]/180*pi)*180/pi));
Best,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With