ANGLEDIFF Difference between two angles. Computes the signed angular difference between two angles in radians. The result is comprised between -PI and +PI. Example A = angleDiff(-pi/4, pi/4) A = 1.5708 % equal to pi/2 A = angleDiff(pi/4, -pi/4) A = -1.5708 % equal to -pi/2 See also angles2d, angleAbsDiff ------ 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 = angleDiff(angle1, angle2) 0002 %ANGLEDIFF Difference between two angles. 0003 % 0004 % Computes the signed angular difference between two angles in radians. 0005 % The result is comprised between -PI and +PI. 0006 % 0007 % Example 0008 % A = angleDiff(-pi/4, pi/4) 0009 % A = 0010 % 1.5708 % equal to pi/2 0011 % A = angleDiff(pi/4, -pi/4) 0012 % A = 0013 % -1.5708 % equal to -pi/2 0014 % 0015 % See also 0016 % angles2d, angleAbsDiff 0017 % 0018 % ------ 0019 % Author: David Legland 0020 % e-mail: david.legland@grignon.inra.fr 0021 % Created: 2011-07-27, using Matlab 7.9.0.529 (R2009b) 0022 % Copyright 2011 INRA - Cepia Software Platform. 0023 0024 % first, normalization 0025 angle1 = normalizeAngle(angle1); 0026 angle2 = normalizeAngle(angle2); 0027 0028 % compute difference and normalize in [-pi pi] 0029 dif = normalizeAngle(angle2 - angle1, 0);