Home > matGeom > geom2d > isPointOnLine.m

isPointOnLine

PURPOSE ^

ISPOINTONLINE Test if a point belongs to a line.

SYNOPSIS ^

function b = isPointOnLine(point, line, varargin)

DESCRIPTION ^

ISPOINTONLINE Test if a point belongs to a line.

   B = isPointOnLine(POINT, LINE)
   with POINT being [xp yp], and LINE being [x0 y0 dx dy].
   Returns 1 if point lies on the line, 0 otherwise.

   If POINT is an N-by-2 array of points, B is a N-by-1 array of booleans.

   If LINE is a N-by-4 array of line, B is a 1-by-N array of booleans.

   B = isPointOnLine(POINT, LINE, TOL)
   Specifies the tolerance used for testing location on 3D line. Default value is 1e-14.

   See also:
   lines2d, points2d, isPointOnEdge, isPointOnRay, isLeftOriented

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function b = isPointOnLine(point, line, varargin)
0002 %ISPOINTONLINE Test if a point belongs to a line.
0003 %
0004 %   B = isPointOnLine(POINT, LINE)
0005 %   with POINT being [xp yp], and LINE being [x0 y0 dx dy].
0006 %   Returns 1 if point lies on the line, 0 otherwise.
0007 %
0008 %   If POINT is an N-by-2 array of points, B is a N-by-1 array of booleans.
0009 %
0010 %   If LINE is a N-by-4 array of line, B is a 1-by-N array of booleans.
0011 %
0012 %   B = isPointOnLine(POINT, LINE, TOL)
0013 %   Specifies the tolerance used for testing location on 3D line. Default value is 1e-14.
0014 %
0015 %   See also:
0016 %   lines2d, points2d, isPointOnEdge, isPointOnRay, isLeftOriented
0017 %
0018 
0019 %   ---------
0020 %   author : David Legland
0021 %   INRA - TPV URPOI - BIA IMASTE
0022 %   created the 31/10/2003.
0023 %
0024 
0025 %   HISTORY
0026 %   11/03/2004 support for multiple inputs
0027 %   08/12/2004 complete implementation, add doc
0028 %   22/05/2009 rename to isPointOnLine, add psb to specify tolerance
0029 %   17/12/2013 replace repmat by bsxfun (faster)
0030 
0031 % extract computation tolerance
0032 tol = 1e-14;
0033 if ~isempty(varargin)
0034     tol = varargin{1};
0035 end
0036 
0037 % test if lines are colinear, using third coordinate of 3D cross-product
0038 % same test as:
0039 % b = abs((xp-x0).*dy-(yp-y0).*dx)./hypot(dx, dy).^2 < tol;
0040 b = bsxfun(...
0041     @rdivide, abs(...
0042     bsxfun(@times, bsxfun(@minus, point(:,1), line(:,1)'), line(:,4)') - ...
0043     bsxfun(@times, bsxfun(@minus, point(:,2), line(:,2)'), line(:,3)')), ...
0044     (line(:,3).^2 + line(:,4).^2)') < tol;
0045

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