Home > matGeom > geom3d > createEdge3d.m

createEdge3d

PURPOSE ^

CREATEEDGE3D Create an edge between two 3D points, or from a 3D line.

SYNOPSIS ^

function edge = createEdge3d(varargin)

DESCRIPTION ^

CREATEEDGE3D Create an edge between two 3D points, or from a 3D line.

   E = createEdge3d(P1, P2)
   Creates the 3D edge joining the two points P1 and P2.

   E = createEdge3d(LIN)
   Creates the 3D edge with same origin and same direction vector as the
   3D line LIN.

   Example
     p1 = [1 1 1];
     p2 = [3 4 5];
     edge = createEdge3d(p1, p2);
     edgeLength3d(edge)
     ans =
         5.3852
   
   See also
     edges3d, drawEdge3d, clipEdge3d, edgelength3d

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function edge = createEdge3d(varargin)
0002 %CREATEEDGE3D Create an edge between two 3D points, or from a 3D line.
0003 %
0004 %   E = createEdge3d(P1, P2)
0005 %   Creates the 3D edge joining the two points P1 and P2.
0006 %
0007 %   E = createEdge3d(LIN)
0008 %   Creates the 3D edge with same origin and same direction vector as the
0009 %   3D line LIN.
0010 %
0011 %   Example
0012 %     p1 = [1 1 1];
0013 %     p2 = [3 4 5];
0014 %     edge = createEdge3d(p1, p2);
0015 %     edgeLength3d(edge)
0016 %     ans =
0017 %         5.3852
0018 %
0019 %   See also
0020 %     edges3d, drawEdge3d, clipEdge3d, edgelength3d
0021 
0022 % ------
0023 % Author: David Legland
0024 % E-mail: david.legland@inrae.fr
0025 % Created: 2018-08-29, using Matlab 9.4.0.813654 (R2018a)
0026 % Copyright 2018-2024 INRA - Cepia Software Platform
0027 
0028 if nargin == 1
0029     % Only one input parameter. Assumes it corresponds to a 3D line with
0030     % 6 params.
0031     var = varargin{1};
0032     
0033     if size(var, 2) ~= 6
0034         error('single input must have 6 columns');
0035     end
0036     
0037     % converts 3D line into 3D edge
0038     edge = zeros(size(var));
0039     edge(:, 1:3) = var(:, 1:3);
0040     edge(:, 4:6) = edge(:, 1:3) + var(:,4:6);
0041     
0042 elseif nargin == 2    
0043     % 2 input parameters correspond to two 3D points
0044     
0045     % extract the two arguments
0046     v1 = varargin{1};
0047     v2 = varargin{2};
0048     
0049     if size(v1, 2) ~= 3 || size(v2, 2) ~= 3
0050         error('Input points must be arrays with 3 columns');
0051     end
0052     
0053     % first input parameter is first point, and second input is the
0054     % second point. Allows multiple points.
0055     n1 = size(v1, 1);
0056     n2 = size(v2, 1);
0057     if n1 == n2
0058         edge = [v1 v2];
0059     elseif n1 == 1 || n2 == 1
0060         edge = [repmat(v1, n2, 1) repmat(v2, n1, 1)];
0061     end
0062     
0063 else
0064     error('Wrong number of arguments in ''%s''', mfilename);
0065 end

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