Home > matGeom > geom2d > createEdge.m

createEdge

PURPOSE ^

CREATEEDGE Create an edge between two points, or from a line.

SYNOPSIS ^

function edge = createEdge(varargin)

DESCRIPTION ^

CREATEEDGE Create an edge between two points, or from a line.

   The internal format for edge representation is given by coordinates of
   two points : [x1 y1 x2 y2].
   This function can serve as a line to edge converter.


   E = createEdge(P1, P2);
   Returns the edge between the two given points P1 and P2.
   
   E = createEdge(x0, y0, dx, dy);
   Returns the edge going through point (x0, y0) and with direction
   vector (dx,dy).

   E = createEdge(param);
   where param is an array of 4 values, creates the edge going through the
   point (param(1) param(2)), and with direction vector given by
   (param(3) param(4)).
   
   E = createEdge(LINE, D);
   create the edge contained in LINE, with same direction and start point,
   but with length given by D.


   Note: in all cases, parameters can be vertical arrays of the same
   dimension. The result is then an array of edges, of dimensions N-by-4.


   See also
   edges2d, lines2d, drawEdge, clipEdge, createLine

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function edge = createEdge(varargin)
0002 %CREATEEDGE Create an edge between two points, or from a line.
0003 %
0004 %   The internal format for edge representation is given by coordinates of
0005 %   two points : [x1 y1 x2 y2].
0006 %   This function can serve as a line to edge converter.
0007 %
0008 %
0009 %   E = createEdge(P1, P2);
0010 %   Returns the edge between the two given points P1 and P2.
0011 %
0012 %   E = createEdge(x0, y0, dx, dy);
0013 %   Returns the edge going through point (x0, y0) and with direction
0014 %   vector (dx,dy).
0015 %
0016 %   E = createEdge(param);
0017 %   where param is an array of 4 values, creates the edge going through the
0018 %   point (param(1) param(2)), and with direction vector given by
0019 %   (param(3) param(4)).
0020 %
0021 %   E = createEdge(LINE, D);
0022 %   create the edge contained in LINE, with same direction and start point,
0023 %   but with length given by D.
0024 %
0025 %
0026 %   Note: in all cases, parameters can be vertical arrays of the same
0027 %   dimension. The result is then an array of edges, of dimensions N-by-4.
0028 %
0029 %
0030 %   See also
0031 %   edges2d, lines2d, drawEdge, clipEdge, createLine
0032 %
0033 
0034 % ------
0035 % Author: David Legland
0036 % E-mail: david.legland@inrae.fr
0037 % Created: 2003-10-31
0038 % Copyright 2003-2024 INRA - TPV URPOI - BIA IMASTE
0039 
0040 if nargin == 1
0041     % Only one input parameter. It can be :
0042     % - line angle
0043     % - array of four parameters
0044     % TODO : add control for arrays of lines.
0045     var = varargin{1};
0046     
0047     if size(var, 2)==4
0048         % 4 parameters of the line in a single array.
0049         %edge = var;
0050         edge = zeros(size(var));
0051         edge(:, 1:2) = var(:,1:2);
0052         edge(:, 3:4) = edge(:, 1:2)+var(:,3:4);
0053     elseif size(var, 2)==1
0054         % 1 parameter : angle of the line, going through origin.
0055         edge = [zeros(size(var,1)) zeros(size(var,1)) cos(var) sin(var)];
0056     else
0057         error('wrong number of dimension for arg1 : can be 1 or 4');
0058     end
0059     
0060 elseif nargin == 2    
0061     % 2 input parameters. They can be :
0062     % - 2 points, then 2 arrays of 1*2 double,
0063     % - a line, and a distance.
0064     
0065     % extract the two arguments
0066     v1 = varargin{1};
0067     v2 = varargin{2};
0068     
0069     if size(v1, 2) == 2
0070         % first input parameter is first point, and second input is the
0071         % second point.
0072         %edge = [v1(:,1), v1(:,2), v2(:,1), v2(:,2)];
0073         edge = [v1 v2];
0074     else
0075         % first input parameter is a line, and second one a distance.
0076         angle = atan2(v1(:,4), v1(:,3));
0077         edge = [v1(:,1), v1(:,2), v1(:,1)+v2.*cos(angle), v1(:,2)+v2.*sin(angle)];
0078     end
0079     
0080 elseif nargin == 3
0081     % 3 input parameters :
0082     % first one is a point belonging to the line,
0083     % second and third ones are direction vector of the line (dx and dy).
0084     p = varargin{1};
0085     edge = [p(:,1) p(:,2) p(:,1)+varargin{2} p(:,2)+varargin{3}];
0086    
0087 elseif nargin == 4
0088     % 4 input parameters :
0089     % they are x0, y0 (point belonging to line) and dx, dy (direction
0090     % vector of the line).
0091     % All parameters should have the same size.
0092     edge = [varargin{1} varargin{2} varargin{1}+varargin{3} varargin{2}+varargin{4}];
0093 else
0094     error('Wrong number of arguments in ''createEdge'' ');
0095 end

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