Home > matGeom > geom2d > angle2Points.m

angle2Points

PURPOSE ^

ANGLE2POINTS Compute horizontal angle between 2 points.

SYNOPSIS ^

function theta = angle2Points(varargin)

DESCRIPTION ^

ANGLE2POINTS Compute horizontal angle between 2 points.

   ALPHA = angle2Points(P1, P2),
   Pi are either [1*2] arrays, or [N*2] arrays, in this case ALPHA is a 
   [N*1] array. The angle computed is the horizontal angle of the line 
   (P1 P2)
   Result is always given in radians, between 0 and 2*pi.

   See Also:
   points2d, angles2d, angle3points, normalizeAngle, vectorAngle


 ---------
 Author: David Legland
 e-mail: david.legland@grignon.inra.fr
 created the 02/03/2007.
 Copyright 2010 INRA - Cepia Software Platform.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function theta = angle2Points(varargin)
0002 %ANGLE2POINTS Compute horizontal angle between 2 points.
0003 %
0004 %   ALPHA = angle2Points(P1, P2),
0005 %   Pi are either [1*2] arrays, or [N*2] arrays, in this case ALPHA is a
0006 %   [N*1] array. The angle computed is the horizontal angle of the line
0007 %   (P1 P2)
0008 %   Result is always given in radians, between 0 and 2*pi.
0009 %
0010 %   See Also:
0011 %   points2d, angles2d, angle3points, normalizeAngle, vectorAngle
0012 %
0013 %
0014 % ---------
0015 % Author: David Legland
0016 % e-mail: david.legland@grignon.inra.fr
0017 % created the 02/03/2007.
0018 % Copyright 2010 INRA - Cepia Software Platform.
0019 
0020 %   HISTORY:
0021 %   2011-01-11 use bsxfun
0022 
0023 % process input arguments
0024 if length(varargin)==2
0025     p1 = varargin{1};
0026     p2 = varargin{2};
0027 elseif length(varargin)==1
0028     var = varargin{1};
0029     p1 = var(1,:);
0030     p2 = var(2,:);
0031 end    
0032 
0033 % ensure data have correct size
0034 n1 = size(p1, 1);
0035 n2 = size(p2, 1);
0036 if n1~=n2 && min(n1, n2)>1
0037     error('angle2Points: wrong size for inputs');
0038 end
0039 
0040 % angle of line (P2 P1), between 0 and 2*pi.
0041 dp = bsxfun(@minus, p2, p1);
0042 theta = mod(atan2(dp(:,2), dp(:,1)) + 2*pi, 2*pi);
0043

Generated on Wed 16-Feb-2022 15:10:47 by m2html © 2003-2019