Home > matGeom > geom2d > bisector.m

bisector

PURPOSE ^

BISECTOR Return the bisector of two lines, or 3 points.

SYNOPSIS ^

function ray = bisector(varargin)

DESCRIPTION ^

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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@inrae.fr
0020 % Created: 2003-10-31
0021 % Copyright 2003-2024 INRA - Cepia Software Platform
0022 
0023 if length(varargin)==2
0024     % two lines
0025     line1 = varargin{1};
0026     line2 = varargin{2};
0027     
0028     point = intersectLines(line1, line2);    
0029     
0030 elseif length(varargin)==3
0031     % three points
0032     p1 = varargin{1};
0033     p2 = varargin{2};
0034     p3 = varargin{3};
0035 
0036     line1 = createLine(p2, p1);
0037     line2 = createLine(p2, p3);
0038     point = p2;
0039     
0040 elseif isscalar(varargin)
0041     % three points, given in one array
0042     var = varargin{1};
0043     p1 = var(1, :);
0044     p2 = var(2, :);
0045     p3 = var(3, :);
0046 
0047     line1 = createLine(p2, p1);
0048     line2 = createLine(p2, p3);
0049     point = p2;
0050 end
0051 
0052 % compute line angles
0053 a1 = lineAngle(line1);
0054 a2 = lineAngle(line2);
0055 
0056 % compute bisector angle (angle of first line + half angle between lines)
0057 angle = mod(a1 + mod(a2-a1+2*pi, 2*pi)/2, pi*2);
0058 
0059 % create the resulting ray
0060 ray = [point cos(angle) sin(angle)];

Generated on Thu 21-Nov-2024 11:30:22 by m2html © 2003-2022