DISTANCEPOINTLINE3D Euclidean distance between 3D point and line. D = distancePointLine3d(POINT, LINE); Returns the distance between point POINT and the line LINE, given as: POINT : [x0 y0 z0] LINE : [x0 y0 z0 dx dy dz] D : (positive) scalar See also lines3d, isPointOnLine3d, distancePointEdge3d, projPointOnLine3d, References http://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html
0001 function d = distancePointLine3d(point, line) 0002 %DISTANCEPOINTLINE3D Euclidean distance between 3D point and line. 0003 % 0004 % D = distancePointLine3d(POINT, LINE); 0005 % Returns the distance between point POINT and the line LINE, given as: 0006 % POINT : [x0 y0 z0] 0007 % LINE : [x0 y0 z0 dx dy dz] 0008 % D : (positive) scalar 0009 % 0010 % See also 0011 % lines3d, isPointOnLine3d, distancePointEdge3d, projPointOnLine3d, 0012 % 0013 % 0014 % References 0015 % http://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html 0016 0017 % ------ 0018 % Author: David Legland 0019 % E-mail: david.legland@inrae.fr 0020 % Created: 2005-05-23 0021 % Copyright 2005-2024 INRA - TPV URPOI - BIA IMASTE 0022 0023 % cf. Mathworld (distance point line 3d) for formula 0024 d = bsxfun(@rdivide, vectorNorm3d( ... 0025 crossProduct3d(line(:,4:6), bsxfun(@minus, line(:,1:3), point)) ), ... 0026 vectorNorm3d(line(:,4:6)));