Home > utilities > tri_from_bndry.m

tri_from_bndry

PURPOSE ^

tesselate a triangular mesh using "triangle" from a single, unclosed boundary

SYNOPSIS ^

function [tri,x,y] = tri_from_bndry(xb,yb,path_to_triangle);

DESCRIPTION ^

 tesselate a triangular mesh using "triangle" from a single, unclosed boundary 

 input:  xb,yb (boundary nodes, unclosed)
         path_to_triangle:  full path to triangle executable ( a string )
 output: tri,x,y (connectivity, nodes)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [tri,x,y] = tri_from_bndry(xb,yb,path_to_triangle); 
0002 % tesselate a triangular mesh using "triangle" from a single, unclosed boundary
0003 %
0004 % input:  xb,yb (boundary nodes, unclosed)
0005 %         path_to_triangle:  full path to triangle executable ( a string )
0006 % output: tri,x,y (connectivity, nodes)
0007 
0008 
0009 % dump poly file
0010 fid = fopen('junk.poly','w');
0011 npts = length(xb);
0012 fprintf(fid,'%d %d %d %d\n',npts,2,1,1);
0013 for i=1:npts
0014   fprintf(fid,'%d %f %f %d %d\n',i,xb(i),yb(i),1,1);
0015 end;
0016 fprintf(fid,'%d %d\n',npts,1);
0017 for i=1:npts-1
0018   fprintf(fid,'%d %d %d %d\n',i,i,i+1,1);  
0019 end;
0020 fprintf(fid,'%d %d %d %d\n',npts,npts,1,1);  
0021 fprintf(fid,'%d\n',0);
0022 fclose(fid);
0023 
0024 % triangulate
0025 system([path_to_triangle ' -pqm -Q junk.poly']);
0026 
0027 % read in the triangulate file
0028 fid = fopen('junk.1.node');
0029 vec = fgetl(fid);
0030 veci = sscanf(vec,'%d %d %d %d');
0031 nvts = veci(1);
0032 b = fscanf(fid,'%d %f %f %d %d',nvts*5); 
0033 a = reshape(b,5,nvts);
0034 x = a(2,:);
0035 y = a(3,:);
0036 fclose(fid);
0037 
0038 fid = fopen('junk.1.ele');
0039 vec = fgetl(fid);
0040 veci = sscanf(vec,'%d %d %d');
0041 nelems = veci(1);
0042 b = fscanf(fid,'%d %d %d %d',nelems*4); 
0043 a = reshape(b,4,nelems);
0044 tri = zeros(nelems,3); 
0045 tri(:,1) = a(2,:); 
0046 tri(:,2) = a(3,:); 
0047 tri(:,3) = a(4,:);

Generated on Wed 20-Feb-2019 16:06:01 by m2html © 2005