AngDiff.m 373 Bytes
Newer Older
Valentin Platzgummer's avatar
Valentin Platzgummer committed
1 2 3 4 5 6 7 8 9 10 11
function [d, e] = AngDiff(x, y)
%ANGDIFF  Compute angle difference accurately
%
%   [d, e] = ANGDIFF(x, y) computes z = y - x, reduced to (-180,180].  d =
%   round(z) and e = z - round(z).  x and y can be any compatible shapes.

  [d, t] = sumx(AngNormalize(-x), AngNormalize(y));
  d = AngNormalize(d);
  d(d == 180 & t > 0) = -180;
  [d, e] = sumx(d, t);
end