ANGLEABSDIFF Absolute difference between two angles. AD = angleAbsDiff(ANGLE1, ANGLE2) Computes the absolute angular difference between two angles in radians. The result is comprised between 0 and PI. Example A = angleAbsDiff(pi/2, pi/3) A = 0.5236 % equal to pi/6 See also angles2d, angleDiff ------ Author: David Legland e-mail: david.legland@grignon.inra.fr Created: 2011-07-27, using Matlab 7.9.0.529 (R2009b) Copyright 2011 INRA - Cepia Software Platform.
0001 function dif = angleAbsDiff(angle1, angle2) 0002 %ANGLEABSDIFF Absolute difference between two angles. 0003 % 0004 % AD = angleAbsDiff(ANGLE1, ANGLE2) 0005 % Computes the absolute angular difference between two angles in radians. 0006 % The result is comprised between 0 and PI. 0007 % 0008 % Example 0009 % A = angleAbsDiff(pi/2, pi/3) 0010 % A = 0011 % 0.5236 % equal to pi/6 0012 % 0013 % See also 0014 % angles2d, angleDiff 0015 % 0016 % ------ 0017 % Author: David Legland 0018 % e-mail: david.legland@grignon.inra.fr 0019 % Created: 2011-07-27, using Matlab 7.9.0.529 (R2009b) 0020 % Copyright 2011 INRA - Cepia Software Platform. 0021 0022 % first, normalization 0023 angle1 = normalizeAngle(angle1); 0024 angle2 = normalizeAngle(angle2); 0025 0026 % compute difference and normalize 0027 dif = normalizeAngle(angle1 - angle2); 0028 dif = min(dif, 2*pi - dif);