ISPOINTONLINE3D Test if a 3D point belongs to a 3D line. B = isPointOnLine3d(POINT, LINE) with POINT being [xp yp zp], and LINE being [x0 y0 z0 dx dy dz]. Returns 1 if point lies on the line, 0 otherwise. If POINT is an N-by-3 array of points, B is a N-by-1 array of booleans. If LINE is a N-by-6 array of lines, B is a N-by-1 array of booleans. B = isPointOnLine3d(POINT, LINE, TOL) Specifies the tolerance used for testing location on 3D line. See also lines3d, distancePointLine3d, linePosition3d, isPointOnLine
0001 function b = isPointOnLine3d(point, line, varargin) 0002 %ISPOINTONLINE3D Test if a 3D point belongs to a 3D line. 0003 % 0004 % B = isPointOnLine3d(POINT, LINE) 0005 % with POINT being [xp yp zp], and LINE being [x0 y0 z0 dx dy dz]. 0006 % Returns 1 if point lies on the line, 0 otherwise. 0007 % 0008 % If POINT is an N-by-3 array of points, B is a N-by-1 array of booleans. 0009 % 0010 % If LINE is a N-by-6 array of lines, B is a N-by-1 array of booleans. 0011 % 0012 % B = isPointOnLine3d(POINT, LINE, TOL) 0013 % Specifies the tolerance used for testing location on 3D line. 0014 % 0015 % See also 0016 % lines3d, distancePointLine3d, linePosition3d, isPointOnLine 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 % size of inputs 0032 np = size(point,1); 0033 nl = size(line, 1); 0034 0035 if np == 1 || nl == 1 || np == nl 0036 % test if lines are colinear, using norm of the cross product 0037 b = bsxfun(@rdivide, vectorNorm3d( ... 0038 crossProduct3d(bsxfun(@minus, line(:,1:3), point), line(:,4:6))), ... 0039 vectorNorm3d(line(:,4:6))) < tol; 0040 else 0041 % same test, but after reshaping arrays to manage difference of 0042 % dimensionality 0043 point = reshape(point, [np 1 3]); 0044 line = reshape(line, [1 nl 6]); 0045 b = bsxfun(@rdivide, vectorNorm3d( ... 0046 cross(bsxfun(@minus, line(:,:,1:3), point), line(ones(1,np),:,4:6), 3)), ... 0047 vectorNorm3d(line(:,:,4:6))) < tol; 0048 end