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 % E-mail: david.legland@inrae.fr
0022 % Created: 2003-10-31
0023 % Copyright 2003-2024 INRA - TPV URPOI - BIA IMASTE
0024 
0025 % extract computation tolerance
0026 tol = 1e-14;
0027 if ~isempty(varargin)
0028     tol = varargin{1};
0029 end
0030 
0031 % test if lines are colinear, using third coordinate of 3D cross-product
0032 % same test as:
0033 % b = abs((xp-x0).*dy-(yp-y0).*dx)./hypot(dx, dy).^2 < tol;
0034 b = bsxfun(...
0035     @rdivide, abs(...
0036     bsxfun(@times, bsxfun(@minus, point(:,1), line(:,1)'), line(:,4)') - ...
0037     bsxfun(@times, bsxfun(@minus, point(:,2), line(:,2)'), line(:,3)')), ...
0038     (line(:,3).^2 + line(:,4).^2)') < tol;
0039

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