Home > matGeom > geom3d > createPlane.m

createPlane

PURPOSE ^

CREATEPLANE Create a plane in parametrized form.

SYNOPSIS ^

function plane = createPlane(varargin)

DESCRIPTION ^

CREATEPLANE Create a plane in parametrized form.

   PLANE = createPlane(P1, P2, P3) 
   creates a plane containing the 3 points

   PLANE = createPlane(PTS) 
   The 3 points are packed into a single 3x3 array.

   PLANE = createPlane(P0, N);
   Creates a plane from a point and from a normal to the plane. The
   parameter N is given either as a 3D vector (1-by-3 row vector), or as
   [THETA PHI], where THETA is the colatitute (angle with the vertical
   axis) and PHI is angle with Ox axis, counted counter-clockwise (both
   given in radians).
 
   PLANE = createPlane(P0, Dip, DipDir);
   Creates a plane from a point and from a dip and dip direction angles 
   of the plane. Parameters Dip and DipDir angles are given as numbers.
   Dip : maximum inclination to the horizontal.
   DipDir : direction of the horizontal trace of the line of dip, 
            measured clockwise from north.

   The created plane data has the following format:
   PLANE = [X0 Y0 Z0  DX1 DY1 DZ1  DX2 DY2 DZ2], with
   - (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
   The 2 direction vectors are normalized and orthogonal.

   See also:
   planes3d, medianPlane

   ---------
   author: David Legland
   INRA - TPV URPOI - BIA IMASTE
   created the 18/02/2005.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function plane = createPlane(varargin)
0002 %CREATEPLANE Create a plane in parametrized form.
0003 %
0004 %   PLANE = createPlane(P1, P2, P3)
0005 %   creates a plane containing the 3 points
0006 %
0007 %   PLANE = createPlane(PTS)
0008 %   The 3 points are packed into a single 3x3 array.
0009 %
0010 %   PLANE = createPlane(P0, N);
0011 %   Creates a plane from a point and from a normal to the plane. The
0012 %   parameter N is given either as a 3D vector (1-by-3 row vector), or as
0013 %   [THETA PHI], where THETA is the colatitute (angle with the vertical
0014 %   axis) and PHI is angle with Ox axis, counted counter-clockwise (both
0015 %   given in radians).
0016 %
0017 %   PLANE = createPlane(P0, Dip, DipDir);
0018 %   Creates a plane from a point and from a dip and dip direction angles
0019 %   of the plane. Parameters Dip and DipDir angles are given as numbers.
0020 %   Dip : maximum inclination to the horizontal.
0021 %   DipDir : direction of the horizontal trace of the line of dip,
0022 %            measured clockwise from north.
0023 %
0024 %   The created plane data has the following format:
0025 %   PLANE = [X0 Y0 Z0  DX1 DY1 DZ1  DX2 DY2 DZ2], with
0026 %   - (X0, Y0, Z0) is a point belonging to the plane
0027 %   - (DX1, DY1, DZ1) is a first direction vector
0028 %   - (DX2, DY2, DZ2) is a second direction vector
0029 %   The 2 direction vectors are normalized and orthogonal.
0030 %
0031 %   See also:
0032 %   planes3d, medianPlane
0033 %
0034 %   ---------
0035 %   author: David Legland
0036 %   INRA - TPV URPOI - BIA IMASTE
0037 %   created the 18/02/2005.
0038 %
0039 
0040 %   HISTORY
0041 %   24/11/2005 add possibility to pack points for plane creation
0042 %   21/08/2006 return normalized planes
0043 %   06/11/2006 update doc for planes created from normal
0044 
0045 if length(varargin) == 1
0046     var = varargin{1};
0047     
0048     if iscell(var)
0049         plane = zeros([length(var) 9]);
0050         for i=1:length(var)
0051             plane(i,:) = createPlane(var{i});
0052         end
0053     elseif size(var, 1) >= 3
0054         % 3 points in a single array
0055         p1 = var(1,:);
0056         p2 = var(2,:);
0057         p3 = var(3,:);
0058         
0059         % create direction vectors
0060         v1 = p2 - p1;
0061         v2 = p3 - p1;
0062 
0063         % create plane
0064         plane = normalizePlane([p1 v1 v2]);
0065         return;
0066     end
0067     
0068 elseif length(varargin) == 2
0069     % plane origin
0070     p0 = varargin{1};
0071     
0072     % second parameter is either a 3D vector or a 3D angle (2 params)
0073     var = varargin{2};
0074     if size(var, 2) == 2
0075         % normal is given in spherical coordinates
0076         n = sph2cart2([var ones(size(var, 1))]);
0077     elseif size(var, 2)==3
0078         % normal is given by a 3D vector
0079         n = normalizeVector3d(var);
0080     else
0081         error ('wrong number of parameters in createPlane');
0082     end
0083     
0084     % ensure same dimension for parameters
0085     if size(p0, 1)==1
0086         p0 = repmat(p0, [size(n, 1) 1]);
0087     end
0088     if size(n, 1)==1
0089         n = repmat(n, [size(p0, 1) 1]);
0090     end
0091 
0092     % find a vector not colinear to the normal
0093     v0 = repmat([1 0 0], [size(p0, 1) 1]);
0094     inds = vectorNorm3d(cross(n, v0, 2))<1e-14;
0095     v0(inds, :) = repmat([0 1 0], [sum(inds) 1]);
0096 %     if abs(cross(n, v0, 2))<1e-14
0097 %         v0 = repmat([0 1 0], [size(p0, 1) 1]);
0098 %     end
0099     
0100     % create direction vectors
0101     v1 = normalizeVector3d(cross(n, v0, 2));
0102     v2 = -normalizeVector3d(cross(v1, n, 2));
0103 
0104     % concatenate result in the array representing the plane
0105     plane = [p0 v1 v2];
0106     return;
0107     
0108 elseif length(varargin)==3
0109     var1 = varargin{1};
0110     var2 = varargin{2};
0111     var3 = varargin{3};
0112     
0113     if size(var1, 2) == 3 && size(var2, 2) == 3 && size(var3, 2) == 3
0114         p1 = var1;    
0115         p2 = var2;
0116         p3 = var3;
0117 
0118         % create direction vectors
0119         v1 = p2 - p1;
0120         v2 = p3 - p1;
0121 
0122         plane = normalizePlane([p1 v1 v2]);
0123         return;
0124     elseif size(var1, 2) == 3 && size(var2, 2) == 1 && size(var3, 2) == 1
0125         p0 = var1;
0126         n = [sin(var2)*sin(var3) sin(var2)*cos(var3) cos(var2)];
0127         
0128         % find a vector not colinear to the normal
0129         v0 = repmat([1 0 0], [size(p0, 1) 1]);
0130         inds = vectorNorm3d(cross(n, v0, 2))<1e-14;
0131         v0(inds, :) = repmat([0 1 0], [sum(inds) 1]);
0132 
0133         % create direction vectors
0134         v1 = normalizeVector3d(cross(n, v0, 2));
0135         v2 = -normalizeVector3d(cross(v1, n, 2));
0136 
0137         % concatenate result in the array representing the plane
0138         plane = [p0 v1 v2];  
0139         return;
0140     else
0141         error('Wrong argument in "createPlane".');
0142     end  
0143 else
0144     error('Wrong number of arguments in "createPlane".');
0145 end
0146

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