Home > matGeom > geom2d > orthogonalLine.m

orthogonalLine

PURPOSE ^

ORTHOGONALLINE Create a line orthogonal to another one through a point.

SYNOPSIS ^

function res = orthogonalLine(line, point)

DESCRIPTION ^

ORTHOGONALLINE Create a line orthogonal to another one through a point.

   PERP = orthogonalLine(LINE, POINT);
   Returns the line orthogonal to the line LINE and going through the
   point given by POINT. Directed angle from LINE to PERP is pi/2.
   LINE is given as [x0 y0 dx dy] and POINT is [xp yp].

   Works also when LINE is a N-by-4 array, or POINT is a N-by-2 array. In
   this case, the result is a N-by-4 array.


 Example
     refLine = createLine([10 10], [30 20]);
     pt = [20 40];
     figure; hold on; axis equal; axis([0 50 0 50]);
     drawLine(refLine, 'lineWidth', 2);
     drawPoint(pt);
     perp = orthogonalLine(refLine, pt);
     drawLine(perp, 'color', 'r');
 
   See also:
   lines2d, parallelLine, intersectLines

   ---------
   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 = orthogonalLine(line, point)
0002 %ORTHOGONALLINE Create a line orthogonal to another one through a point.
0003 %
0004 %   PERP = orthogonalLine(LINE, POINT);
0005 %   Returns the line orthogonal to the line LINE and going through the
0006 %   point given by POINT. Directed angle from LINE to PERP is pi/2.
0007 %   LINE is given as [x0 y0 dx dy] and POINT is [xp yp].
0008 %
0009 %   Works also when LINE is a N-by-4 array, or POINT is a N-by-2 array. In
0010 %   this case, the result is a N-by-4 array.
0011 %
0012 %
0013 % Example
0014 %     refLine = createLine([10 10], [30 20]);
0015 %     pt = [20 40];
0016 %     figure; hold on; axis equal; axis([0 50 0 50]);
0017 %     drawLine(refLine, 'lineWidth', 2);
0018 %     drawPoint(pt);
0019 %     perp = orthogonalLine(refLine, pt);
0020 %     drawLine(perp, 'color', 'r');
0021 %
0022 %   See also:
0023 %   lines2d, parallelLine, intersectLines
0024 %
0025 %   ---------
0026 %   author : David Legland
0027 %   INRA - TPV URPOI - BIA IMASTE
0028 %   created the 31/10/2003.
0029 %
0030 
0031 %   HISTORY
0032 %   19/02/2004 added control for multiple lines and/or points
0033 %   31/12/2013 added example
0034 
0035 N = max(size(point, 1), size(line, 1));
0036 
0037 if size(point, 1)>1
0038     res = point;
0039 else
0040     res = ones(N, 1)*point;
0041 end
0042 
0043 if size(line, 1)>1
0044     res(:,3) = -line(:,4);
0045     res(:,4) = line(:,3);
0046 else
0047     res(:,3) = -ones(N,1)*line(4);
0048     res(:,4) = ones(N,1)*line(3);
0049 end
0050

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