Home > matGeom > geom2d > parallelLine.m

parallelLine

PURPOSE ^

PARALLELLINE Create a line parallel to another one.

SYNOPSIS ^

function res = parallelLine(line, point)

DESCRIPTION ^

PARALLELLINE Create a line parallel to another one.

   RES = parallelLine(LINE, POINT);
   Returns the line with same direction vector than LINE and going through
   the point given by POINT. 
   LINE is given as [x0 y0 dx dy] and POINT is [xp yp].


   RES = parallelLine(LINE, DIST);
   Uses relative distance to specify position. The new line will be
   located at distance DIST, counted positive in the right side of LINE
   and negative in the left side.

   Examples
     P1 = [20 30]; P2 = [50 10];
     L1 = createLine([50 10], [20 30]);
     figure; hold on; axis equal; axis([0 60 0 50]);
     drawPoint([P1; P2], 'ko');
     drawLine(L1, 'k');
     P = [30 40];
     drawPoint(P, 'ko');
     L2 = parallelLine(L1, P);
     drawLine(L2, 'Color', 'b');

   See also:
   lines2d, orthogonalLine, distancePointLine, parallelEdge

   ---------

   author : David Legland
   INRA - TPV URPOI - BIA IMASTE
   created the 31/10/2003.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function res = parallelLine(line, point)
0002 %PARALLELLINE Create a line parallel to another one.
0003 %
0004 %   RES = parallelLine(LINE, POINT);
0005 %   Returns the line with same direction vector than LINE and going through
0006 %   the point given by POINT.
0007 %   LINE is given as [x0 y0 dx dy] and POINT is [xp yp].
0008 %
0009 %
0010 %   RES = parallelLine(LINE, DIST);
0011 %   Uses relative distance to specify position. The new line will be
0012 %   located at distance DIST, counted positive in the right side of LINE
0013 %   and negative in the left side.
0014 %
0015 %   Examples
0016 %     P1 = [20 30]; P2 = [50 10];
0017 %     L1 = createLine([50 10], [20 30]);
0018 %     figure; hold on; axis equal; axis([0 60 0 50]);
0019 %     drawPoint([P1; P2], 'ko');
0020 %     drawLine(L1, 'k');
0021 %     P = [30 40];
0022 %     drawPoint(P, 'ko');
0023 %     L2 = parallelLine(L1, P);
0024 %     drawLine(L2, 'Color', 'b');
0025 %
0026 %   See also:
0027 %   lines2d, orthogonalLine, distancePointLine, parallelEdge
0028 %
0029 %   ---------
0030 %
0031 %   author : David Legland
0032 %   INRA - TPV URPOI - BIA IMASTE
0033 %   created the 31/10/2003.
0034 %
0035 
0036 %   HISTORY
0037 %   31/07/2005 add usage of distance
0038 %   15/06/2009 change convention for distance sign
0039 %   31/09/2012 adapt for multiple lines
0040 
0041 if size(point, 2) == 1
0042     % use a distance. Compute position of point located at distance DIST on
0043     % the line orthogonal to the first one.
0044     point = pointOnLine([line(:,1) line(:,2) line(:,4) -line(:,3)], point);
0045 end
0046 
0047 % normal case: compute line through a point with given direction
0048 res = zeros(size(line, 1), 4);
0049 res(:, 1:2) = point;
0050 res(:, 3:4) = line(:, 3:4);

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