I have a GPS track log, I have registered the heading of navigation (i.e. for every logged point I have trace the heading). As far as I observed, this heading vary between 0 and 360. So, in log we can find:
- 0.002
- 0.1
- 359.2
- 0.01
Consider now point 3 and 4. Obviously, the car hasn't perform a 360 rotation. It just moves few degree (0.81) on another heading trajectory. So the margin is not abs(359.2-0.01) or abs(0.01-359.2). I clearly need a more sophisticated way to compute the changing. I think that I need to compute abs(359.2-0.01)=359.19 and next 360-359.19=0.81. Can I consider this as my standard modus operandi to compute direction change? I'm on matlab, so maybe there's a way to do this directly?
This might do what you want:
mod(a-b+180, 360) - 180
Example:
>> f = @(a,b) mod(a-b+180, 360) - 180;
>> f(359.2, 0.01)
ans = -0.81000
>> f(0.01, 359.2)
ans = 0.81000
>> f(358.2, 359.2)
ans = -1
>> f(0.01, 1.01)
ans = -1