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
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@inra.fr 0025 % Created: 2018-08-29, using Matlab 9.4.0.813654 (R2018a) 0026 % Copyright 2018 INRA - Cepia Software Platform. 0027 0028 0029 if nargin == 1 0030 % Only one input parameter. Assumes it corresponds to a 3D line with 0031 % 6 params. 0032 var = varargin{1}; 0033 0034 if size(var, 2) ~= 6 0035 error('single input must have 6 columns'); 0036 end 0037 0038 % converts 3D line into 3D edge 0039 edge = zeros(size(var)); 0040 edge(:, 1:3) = var(:, 1:3); 0041 edge(:, 4:6) = edge(:, 1:3) + var(:,4:6); 0042 0043 elseif nargin == 2 0044 % 2 input parameters correspond to two 3D points 0045 0046 % extract the two arguments 0047 v1 = varargin{1}; 0048 v2 = varargin{2}; 0049 0050 if size(v1, 2) ~= 3 || size(v2, 2) ~= 3 0051 error('Input points must be arrays with 3 columns'); 0052 end 0053 0054 % first input parameter is first point, and second input is the 0055 % second point. Allows multiple points. 0056 n1 = size(v1, 1); 0057 n2 = size(v2, 1); 0058 if n1 == n2 0059 edge = [v1 v2]; 0060 elseif n1 == 1 || n2 == 1 0061 edge = [repmat(v1, n2, 1) repmat(v2, n1, 1)]; 0062 end 0063 0064 else 0065 error('Wrong number of arguments in ''%s''', mfilename); 0066 end