Home > matGeom > meshes3d > triangulateCurvePair.m

triangulateCurvePair

PURPOSE ^

TRIANGULATECURVEPAIR Compute triangulation between a pair of 3D open curves.

SYNOPSIS ^

function [vertices, facets] = triangulateCurvePair(curve1, curve2)

DESCRIPTION ^

TRIANGULATECURVEPAIR Compute triangulation between a pair of 3D open curves.

   [V, F] = testTriangulateCurvePair(CURVE1, CURVE2)

   Example
     % triangulate a surface patch between two open curves
     % create two sample curves
     t = linspace(0, 2*pi, 100);
     curve1 = [linspace(0, 10, 100)' 5 * sin(t') zeros(100,1)];
     curve2 = [linspace(0, 10, 100)' 2 * sin(t') 2*ones(100,1)];
     figure; hold on;
     drawPolyline3d(curve1, 'b');
     drawPolyline3d(curve2, 'g');
     view(3); axis equal;
     [v, f] = triangulateCurvePair(curve1, curve2);
     figure; drawMesh(v, f, 'linestyle', 'none');
     view(3); axis equal

   See also
     meshes3D, triangulatePolygonPair, meshSurfaceArea

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [vertices, facets] = triangulateCurvePair(curve1, curve2)
0002 %TRIANGULATECURVEPAIR Compute triangulation between a pair of 3D open curves.
0003 %
0004 %   [V, F] = testTriangulateCurvePair(CURVE1, CURVE2)
0005 %
0006 %   Example
0007 %     % triangulate a surface patch between two open curves
0008 %     % create two sample curves
0009 %     t = linspace(0, 2*pi, 100);
0010 %     curve1 = [linspace(0, 10, 100)' 5 * sin(t') zeros(100,1)];
0011 %     curve2 = [linspace(0, 10, 100)' 2 * sin(t') 2*ones(100,1)];
0012 %     figure; hold on;
0013 %     drawPolyline3d(curve1, 'b');
0014 %     drawPolyline3d(curve2, 'g');
0015 %     view(3); axis equal;
0016 %     [v, f] = triangulateCurvePair(curve1, curve2);
0017 %     figure; drawMesh(v, f, 'linestyle', 'none');
0018 %     view(3); axis equal
0019 %
0020 %   See also
0021 %     meshes3D, triangulatePolygonPair, meshSurfaceArea
0022  
0023 % ------
0024 % Author: David Legland
0025 % e-mail: david.legland@inra.fr
0026 % Created: 2017-05-18,    using Matlab 9.1.0.441655 (R2016b)
0027 % Copyright 2017 INRA - Cepia Software Platform.
0028 
0029 
0030 %% Memory allocation
0031 
0032 % number of vertices on each curve
0033 n1 = size(curve1, 1);
0034 n2 = size(curve2, 1);
0035 
0036 % allocate the array of facets (each edge of each curve provides a facet)
0037 nFacets = n1 + n2 - 2;
0038 facets = zeros(nFacets, 3);
0039 
0040 % look for the closest ends of two curves and reverse the second curve if
0041 % needed
0042 p1 = curve1(1, :);
0043 if distancePoints(p1, curve2(1,:)) > distancePoints(p1, curve2(end,:))
0044     curve2 = curve2(end:-1:1,:);
0045 end
0046 currentIndex1 = 1;
0047 currentIndex2 = 1;
0048 
0049 % concatenate vertex coordinates for creating mesh
0050 vertices = [curve1 ; curve2];
0051 
0052 
0053 
0054 %% Main iteration
0055 % For each diagonal, consider the two possible facets (one for each 'next'
0056 % vertex on each curve), each create current facet according to the closest
0057 % one.
0058 % Then update current diagonal for next iteration.
0059 
0060 for i = 1:nFacets
0061     nextIndex1 = mod(currentIndex1, n1) + 1;
0062     nextIndex2 = mod(currentIndex2, n2) + 1;
0063     
0064     % compute lengths of diagonals
0065     dist1 = distancePoints(curve1(currentIndex1, :), curve2(nextIndex2,:));
0066     dist2 = distancePoints(curve1(nextIndex1, :), curve2(currentIndex2,:));
0067     
0068     if dist1 < dist2
0069         % keep current vertex of curve1, use next vertex on curve2
0070         facet = [currentIndex1 currentIndex2+n1 nextIndex2+n1];
0071         currentIndex2 = nextIndex2;
0072     else
0073         % keep current vertex of curve2, use next vertex on curve1
0074         facet = [currentIndex1 currentIndex2+n1 nextIndex1];
0075         currentIndex1 = nextIndex1;
0076     end
0077     
0078     % create the facet
0079     facets(i, :) = facet;
0080 end
0081

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