BISECTOR Return the bisector of two lines, or 3 points. RAY = bisector(LINE1, LINE2); create the bisector of the two lines, given as [x0 y0 dx dy]. RAY = bisector(P1, P2, P3); create the bisector of lines (P2 P1) and (P2 P3). The result has the form [x0 y0 dx dy], with [x0 y0] being the origin point ans [dx dy] being the direction vector, normalized to have unit norm. See also: lines2d, rays2d --------- Author: David Legland e-mail: david.legland@grignon.inra.fr created the 31/10/2003. Copyright 2010 INRA - Cepia Software Platform.
0001 function ray = bisector(varargin) 0002 %BISECTOR Return the bisector of two lines, or 3 points. 0003 % 0004 % RAY = bisector(LINE1, LINE2); 0005 % create the bisector of the two lines, given as [x0 y0 dx dy]. 0006 % 0007 % RAY = bisector(P1, P2, P3); 0008 % create the bisector of lines (P2 P1) and (P2 P3). 0009 % 0010 % The result has the form [x0 y0 dx dy], with [x0 y0] being the origin 0011 % point ans [dx dy] being the direction vector, normalized to have unit 0012 % norm. 0013 % 0014 % See also: 0015 % lines2d, rays2d 0016 % 0017 % --------- 0018 % Author: David Legland 0019 % e-mail: david.legland@grignon.inra.fr 0020 % created the 31/10/2003. 0021 % Copyright 2010 INRA - Cepia Software Platform. 0022 0023 % HISTORY 0024 % 2005-07-07 add bisector of 3 points 0025 % 2010-11-05 ode cleanup 0026 0027 if length(varargin)==2 0028 % two lines 0029 line1 = varargin{1}; 0030 line2 = varargin{2}; 0031 0032 point = intersectLines(line1, line2); 0033 0034 elseif length(varargin)==3 0035 % three points 0036 p1 = varargin{1}; 0037 p2 = varargin{2}; 0038 p3 = varargin{3}; 0039 0040 line1 = createLine(p2, p1); 0041 line2 = createLine(p2, p3); 0042 point = p2; 0043 0044 elseif length(varargin)==1 0045 % three points, given in one array 0046 var = varargin{1}; 0047 p1 = var(1, :); 0048 p2 = var(2, :); 0049 p3 = var(3, :); 0050 0051 line1 = createLine(p2, p1); 0052 line2 = createLine(p2, p3); 0053 point = p2; 0054 end 0055 0056 % compute line angles 0057 a1 = lineAngle(line1); 0058 a2 = lineAngle(line2); 0059 0060 % compute bisector angle (angle of first line + half angle between lines) 0061 angle = mod(a1 + mod(a2-a1+2*pi, 2*pi)/2, pi*2); 0062 0063 % create the resulting ray 0064 ray = [point cos(angle) sin(angle)];