LINEANGLE Computes angle between two straight lines. A = lineAngle(LINE); Returns the angle between horizontal, right-axis and the given line. Angle is given in radians, between 0 and 2*pi, in counter-clockwise direction. A = lineAngle(LINE1, LINE2); Returns the directed angle between the two lines. Angle is given in radians between 0 and 2*pi, in counter-clockwise direction. See also lines2d, angles2d, createLine, normalizeAngle --------- author : David Legland INRA - TPV URPOI - BIA IMASTE created the 31/10/2003.
0001 function theta = lineAngle(varargin) 0002 %LINEANGLE Computes angle between two straight lines. 0003 % 0004 % A = lineAngle(LINE); 0005 % Returns the angle between horizontal, right-axis and the given line. 0006 % Angle is given in radians, between 0 and 2*pi, in counter-clockwise 0007 % direction. 0008 % 0009 % A = lineAngle(LINE1, LINE2); 0010 % Returns the directed angle between the two lines. Angle is given in 0011 % radians between 0 and 2*pi, in counter-clockwise direction. 0012 % 0013 % See also 0014 % lines2d, angles2d, createLine, normalizeAngle 0015 % 0016 % --------- 0017 % author : David Legland 0018 % INRA - TPV URPOI - BIA IMASTE 0019 % created the 31/10/2003. 0020 % 0021 0022 % HISTORY 0023 % 2004-02-19 added support for multiple lines. 0024 % 2011-01-20 use bsxfun 0025 0026 nargs = length(varargin); 0027 if nargs == 1 0028 % angle of one line with horizontal 0029 line = varargin{1}; 0030 theta = mod(atan2(line(:,4), line(:,3)) + 2*pi, 2*pi); 0031 0032 elseif nargs==2 0033 % angle between two lines 0034 theta1 = lineAngle(varargin{1}); 0035 theta2 = lineAngle(varargin{2}); 0036 theta = mod(bsxfun(@minus, theta2, theta1)+2*pi, 2*pi); 0037 end