Home > matGeom > geom3d > planePosition.m

planePosition

PURPOSE ^

PLANEPOSITION Compute position of a point on a plane.

SYNOPSIS ^

function pos = planePosition(point, plane)

DESCRIPTION ^

PLANEPOSITION Compute position of a point on a plane.

   PT2 = planePosition(POINT, PLANE)
   POINT has format [X Y Z], and plane has format
   [X0 Y0 Z0  DX1 DY1 DZ1  DX2 DY2 DZ2], where :
   - (X0, Y0, Z0) is a point belonging to the plane
   - (DX1, DY1, DZ1) is a first direction vector
   - (DX2, DY2, DZ2) is a second direction vector

   Result PT2 has the form [XP YP], with [XP YP] coordinate of the point
   in the coordinate system of the plane.

   
   CAUTION:
   WORKS ONLY FOR PLANES WITH ORTHOGONAL DIRECTION VECTORS

   Example
     plane = [10 20 30  1 0 0  0 1 0];
     point = [13 24 35];
     pos = planePosition(point, plane)
     pos = 
         3   4

   See also:
   geom3d, planes3d, points3d, planePoint

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function pos = planePosition(point, plane)
0002 %PLANEPOSITION Compute position of a point on a plane.
0003 %
0004 %   PT2 = planePosition(POINT, PLANE)
0005 %   POINT has format [X Y Z], and plane has format
0006 %   [X0 Y0 Z0  DX1 DY1 DZ1  DX2 DY2 DZ2], where :
0007 %   - (X0, Y0, Z0) is a point belonging to the plane
0008 %   - (DX1, DY1, DZ1) is a first direction vector
0009 %   - (DX2, DY2, DZ2) is a second direction vector
0010 %
0011 %   Result PT2 has the form [XP YP], with [XP YP] coordinate of the point
0012 %   in the coordinate system of the plane.
0013 %
0014 %
0015 %   CAUTION:
0016 %   WORKS ONLY FOR PLANES WITH ORTHOGONAL DIRECTION VECTORS
0017 %
0018 %   Example
0019 %     plane = [10 20 30  1 0 0  0 1 0];
0020 %     point = [13 24 35];
0021 %     pos = planePosition(point, plane)
0022 %     pos =
0023 %         3   4
0024 %
0025 %   See also:
0026 %   geom3d, planes3d, points3d, planePoint
0027 
0028 %   ---------
0029 %   author : David Legland
0030 %   INRA - TPV URPOI - BIA IMASTE
0031 %   created the 21/02/2005.
0032 %
0033 
0034 %   HISTORY
0035 %   24/11/2005 add support for multiple inputs
0036 
0037 % size of input arguments
0038 npl = size(plane, 1);
0039 npt = size(point, 1);
0040 
0041 % check inputs have compatible sizes
0042 if npl ~= npt && npl > 1 && npt > 1
0043     error('geom3d:planePoint:inputSize', ...
0044         'plane and point should have same size, or one of them must have 1 row');
0045 end
0046 
0047 % origin and direction vectors of the plane
0048 p0 = plane(:, 1:3);
0049 d1 = plane(:, 4:6);
0050 d2 = plane(:, 7:9);
0051 
0052 % Compute dot products with direction vectors of the plane
0053 if npl > 1 || npt == 1
0054     s = dot(bsxfun(@minus, point, p0), d1, 2) ./ vectorNorm3d(d1);
0055     t = dot(bsxfun(@minus, point, p0), d2, 2) ./ vectorNorm3d(d2);
0056 else
0057     % we have npl == 1 and npt > 1
0058     d1 = d1 / vectorNorm3d(d1);
0059     d2 = d2 / vectorNorm3d(d2);
0060     inds = ones(npt,1);
0061     s = dot(bsxfun(@minus, point, p0), d1(inds, :), 2);
0062     t = dot(bsxfun(@minus, point, p0), d2(inds, :), 2);
0063 end
0064 
0065 % % old version:
0066 % s = dot(point-p0, d1, 2) ./ vectorNorm3d(d1);
0067 % t = dot(point-p0, d2, 2) ./ vectorNorm3d(d2);
0068 
0069 pos = [s t];
0070

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