Home > matGeom > geom3d > createLine3d.m

createLine3d

PURPOSE ^

CREATELINE3D Create a line with various inputs.

SYNOPSIS ^

function line = createLine3d(varargin)

DESCRIPTION ^

CREATELINE3D Create a line with various inputs.

   Line is represented in a parametric form : [x0 y0 z0 dx dy dz]
       x = x0 + t*dx
       y = y0 + t*dy;
       z = z0 + t*dz;


   L = createLine3d(P1, P2);
   Returns the line going through the two given points P1 and P2.
   
   L = createLine3d(X0, Y0, Z0, DX, DY, DZ);
   Returns the line going through the point [x0, y0, z0], and with
   direction vector given by [DX DY DZ]. 

   L = createLine3d(P0, DX, DY, DZ);
   Returns the line going through point P0 given by [x0, y0, z0] and with
   direction vector given by [DX DY DZ]. 

   L = createLine3d(THETA, PHI);
   Create a line originated at (0,0) and with angles theta and phi.

   L = createLine3d(P0, THETA, PHI);
   Create a line with direction given by theta and phi, and which contains
   point P0. 


   Note : in all cases, parameters can be vertical arrays of the same
   dimension. The result is then an array of lines, of dimensions [N*6].

   See also
   lines3d

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function line = createLine3d(varargin)
0002 %CREATELINE3D Create a line with various inputs.
0003 %
0004 %   Line is represented in a parametric form : [x0 y0 z0 dx dy dz]
0005 %       x = x0 + t*dx
0006 %       y = y0 + t*dy;
0007 %       z = z0 + t*dz;
0008 %
0009 %
0010 %   L = createLine3d(P1, P2);
0011 %   Returns the line going through the two given points P1 and P2.
0012 %
0013 %   L = createLine3d(X0, Y0, Z0, DX, DY, DZ);
0014 %   Returns the line going through the point [x0, y0, z0], and with
0015 %   direction vector given by [DX DY DZ].
0016 %
0017 %   L = createLine3d(P0, DX, DY, DZ);
0018 %   Returns the line going through point P0 given by [x0, y0, z0] and with
0019 %   direction vector given by [DX DY DZ].
0020 %
0021 %   L = createLine3d(THETA, PHI);
0022 %   Create a line originated at (0,0) and with angles theta and phi.
0023 %
0024 %   L = createLine3d(P0, THETA, PHI);
0025 %   Create a line with direction given by theta and phi, and which contains
0026 %   point P0.
0027 %
0028 %
0029 %   Note : in all cases, parameters can be vertical arrays of the same
0030 %   dimension. The result is then an array of lines, of dimensions [N*6].
0031 %
0032 %   See also
0033 %   lines3d
0034 
0035 % ------
0036 % Author: David Legland
0037 % E-mail: david.legland@inrae.fr
0038 % Created: 2005-02-17
0039 % Copyright 2005-2024 INRA - TPV URPOI - BIA IMASTE
0040 
0041 %   NOTE : A 3d line can also be represented with a 1*7 array :
0042 %   [x0 y0 z0 dx dy dz t].
0043 %   whith 't' being one of the following :
0044 %   - t=0 : line is a singleton (x0,y0)
0045 %   - t=1 : line is an edge segment, between points (x0,y0) and (x0+dx,
0046 %   y0+dy).
0047 %   - t=Inf : line is a Ray, originated from (x0,y0) and going to infinity
0048 %   in the direction(dx,dy).
0049 %   - t=-Inf : line is a Ray, originated from (x0,y0) and going to infinity
0050 %   in the direction(-dx,-dy).
0051 %   - t=NaN : line is a real straight line, and contains all points
0052 %   verifying the above equation.
0053 %   This seems to be a convenient way to represent uniformly all kind of
0054 %   lines (including edges, rays, and even point).
0055 %
0056 %   NOTE2 : Another form is the 1*8 array :
0057 %   [x0 y0 z0 dx dy dz t1 t2].
0058 %   with t1 and t2 giving first and last position of the edge on the
0059 %   supporting straight line, and with t2>t1.
0060 
0061 if isscalar(varargin)    
0062     error('Wrong number of arguments in ''createLine'' ');
0063     
0064 elseif length(varargin)==2    
0065     % 2 input parameters. They can be :
0066     % - 2 points, then 2 arrays of 1*2 double.
0067     v1 = varargin{1};
0068     v2 = varargin{2};
0069     if size(v1, 2)==3
0070         % first input parameter is first point, and second input is the
0071         % second point.
0072         line = [v1(:,1) v1(:,2) v1(:,3) v2(:,1)-v1(:,1) v2(:,2)-v1(:,2) v2(:,3)-v1(:,3)];    
0073     elseif size(v1, 2)==1
0074         % first parameter is angle with the vertical
0075         % second parameter is horizontal angle with Ox axis
0076         theta = varargin{1};
0077         phi = varargin{2};
0078 
0079         sit = sin(theta);
0080         p0 = zeros([size(theta, 1) 3]);
0081         
0082         line = [p0 cos(phi)*sit sin(phi)*sit cos(theta)];
0083     end
0084     
0085 elseif length(varargin)==3
0086     % 3 input parameters :
0087     % first parameter is a point of the line
0088     % second parameter is angle with the vertical
0089     % third parameter is horizontal angle with Ox axis
0090     p0      = varargin{1};
0091     theta   = varargin{2}; 
0092     phi     = varargin{3};
0093     
0094     if size(p0, 2)~=3
0095         error('first argument should be a 3D point');
0096     end
0097     
0098     sit = sin(theta);
0099     line = [p0 cos(phi)*sit sin(phi)*sit cos(theta)];
0100     
0101 elseif length(varargin)==4
0102     % 4 input parameters :
0103     p0 = varargin{1};
0104     dx = varargin{2};
0105     dy = varargin{3};
0106     dz = varargin{4};
0107     
0108     if size(p0, 2)~=3
0109         error('first argument should be a 3D point');
0110     end
0111     
0112     line = [p0 dx dy dz];
0113 elseif length(varargin)==5
0114     % 5 input parameters :
0115     % first parameter is distance of lin to origin
0116     % second parameter is angle with the vertical
0117     % third parameter is horizontal angle with Ox axis
0118     x0      = varargin{1};
0119     y0      = varargin{1};
0120     z0      = varargin{1};
0121     theta   = varargin{2}; 
0122     phi     = varargin{3};
0123     
0124     sit = sin(theta);
0125     line = [x0 y0 z0 cos(phi)*sit sin(phi)*sit cos(theta)];
0126 
0127 elseif length(varargin)==6
0128     % 6 input parameters, given as separate arguments for x0, y0, z0 and
0129     % dx, dy and dz
0130     % (not very useful, but anyway...)
0131     x0 = varargin{1};
0132     y0 = varargin{2};
0133     z0 = varargin{3};
0134     dx = varargin{4};
0135     dy = varargin{5};
0136     dz = varargin{6};
0137 
0138     line = [x0 y0 z0 dx dy dz];
0139 end

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