Home > matGeom > geom3d > linePosition3d.m

linePosition3d

PURPOSE ^

LINEPOSITION3D Return the position of a 3D point projected on a 3D line.

SYNOPSIS ^

function pos = linePosition3d(point, line)

DESCRIPTION ^

LINEPOSITION3D Return the position of a 3D point projected on a 3D line.

   Note: deprecated, replaced by 'line3dPosition'

   T = linePosition3d(POINT, LINE)
   Computes position of point POINT on the line LINE, relative to origin
   point and direction vector of the line.
   LINE has the form [x0 y0 z0 dx dy dy],
   POINT has the form [x y z], and is assumed to belong to line.
   The result T is the value such that POINT = LINE(1:3) + T * LINE(4:6).
   If POINT does not belong to LINE, the position of its orthogonal
   projection is computed instead. 

   T = linePosition3d(POINT, LINES)
   If LINES is an array of NL lines, return NL positions, corresponding to
   each line.

   T = linePosition3d(POINTS, LINE)
   If POINTS is an array of NP points, return NP positions, corresponding
   to each point.

   See also
   lines3d, createLine3d, distancePointLine3d, projPointOnLine3d

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function pos = linePosition3d(point, line)
0002 %LINEPOSITION3D Return the position of a 3D point projected on a 3D line.
0003 %
0004 %   Note: deprecated, replaced by 'line3dPosition'
0005 %
0006 %   T = linePosition3d(POINT, LINE)
0007 %   Computes position of point POINT on the line LINE, relative to origin
0008 %   point and direction vector of the line.
0009 %   LINE has the form [x0 y0 z0 dx dy dy],
0010 %   POINT has the form [x y z], and is assumed to belong to line.
0011 %   The result T is the value such that POINT = LINE(1:3) + T * LINE(4:6).
0012 %   If POINT does not belong to LINE, the position of its orthogonal
0013 %   projection is computed instead.
0014 %
0015 %   T = linePosition3d(POINT, LINES)
0016 %   If LINES is an array of NL lines, return NL positions, corresponding to
0017 %   each line.
0018 %
0019 %   T = linePosition3d(POINTS, LINE)
0020 %   If POINTS is an array of NP points, return NP positions, corresponding
0021 %   to each point.
0022 %
0023 %   See also
0024 %   lines3d, createLine3d, distancePointLine3d, projPointOnLine3d
0025 
0026 % ------
0027 % Author: David Legland
0028 % E-mail: david.legland@inrae.fr
0029 % Created: 2005-02-17
0030 % Copyright 2005-2024 INRA - TPV URPOI - BIA IMASTE
0031 
0032 % deprecation warning
0033 warning('geom3d:deprecated', ...
0034     '''linePosition3d'' is deprecated, use ''line3dPosition'' instead');
0035 
0036 % size of input arguments
0037 np = size(point, 1);
0038 nl = size(line, 1);
0039 
0040 if np == 1 || nl == 1 || np == nl
0041     % standard case where result is either scalar or vector
0042     
0043     % vector from line origin to point
0044     dp = bsxfun(@minus, point, line(:,1:3));
0045     
0046     % direction vector of the line
0047     vl = line(:, 4:6);
0048     
0049     % precompute and check validity of denominator
0050     denom = sum(vl.^2, 2);
0051     invalidLine = denom < eps;
0052     denom(invalidLine) = 1;
0053     
0054     % compute position using dot product normalized with norm of line vector.
0055     pos = bsxfun(@rdivide, sum(bsxfun(@times, dp, vl), 2), denom);
0056     
0057     % position on a degenerated line is set to 0
0058     pos(invalidLine) = 0;
0059 
0060 else
0061     % reshape input
0062     point = reshape(point, [np 1 3]);
0063     line = reshape(line, [1 nl 6]);
0064     
0065     % vector from line origin to point
0066     dp = bsxfun(@minus, point, line(:,:,1:3));
0067     
0068     % direction vector of the line
0069     vl = line(:, :, 4:6);
0070     
0071     % precompute and check validity of denominator
0072     denom = sum(vl.^2, 3);
0073     invalidLine = denom < eps;
0074     denom(invalidLine) = 1;
0075     
0076     % compute position using dot product normalized with norm of line vector.
0077     pos = bsxfun(@rdivide, sum(bsxfun(@times, dp, vl), 3), denom);
0078     
0079     % position on a degenerated line is set to 0
0080     pos(invalidLine) = 0;
0081 end

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