When exporting a triangulation as an stl using stlwrite() the resulting stl is missing half of its faces.
I get an output file looking like the following picture when trying to export my triangulation object as an stl. the yellow represents valid faces and the red corresponds to missing faces. The section of code where I generate the face connectivity and convert to a triangulation object and subsequently an stl file.
Each "loadpath" (wiggly strand connecting one rectangle to the other) is defined in 2-d by a set of 2 1001 point curves, and in 3-d by a simple upwards translation of those curves. The matrix containing my points starts with 4 points defining the -z corners of the -x grip stock (rectangular section), followed by the +y and -y curves defining each of the loadpaths on the -z face of the object, then the 4 points defining the -z corners of the +x grip stock, the 4 points defining the +z corners of the -x grip stock, the upper loadpaths, and finally the 4 corners defining the +z corners of the +x grip stock.
% Generating tringular tiling of the loadpaths
f=zeros(3,2001*10*4);
for i=1:1000 % first loadpath
f(:,i)=[i,i+1,1001+i]; %y+ layer of triangles on bottom face
f(:,1000+i)=[i+1,1001+i,1002+i]; %y- layer of triangles on bottom face
f(:,20000+i)=[i,i+1,20028+i]; %z- layer of triangles on y+ face
f(:,21000+i)=[i+1,20028+i,20029+i]; %z+ layer of tringles on y+ face
f(:,40000+i)=[1001+i,1002+i,21029+i];
f(:,41000+i)=[1002+i,21029+i,21030+i];
f(:,60000+i)=[20028+i,20029+i,21029+i];
f(:,61000+i)=[20029+i,21029+i,21030+i];
end
for i=1:9 % loadpaths 2-10
f(:,((2000*i)+1):((2000*(i+1))))=f(:,1:2000)+2002*i;
f(:,((2000*i)+20000+1):(2000*(i+1)+20000))=f(:,20001:22000)+2002*i;
f(:,((2000*i)+40000+1):(2000*(i+1)+40000))=f(:,40001:42000)+2002*i;
f(:,((2000*i)+60000+1):(2000*(i+1)+60000))=f(:,60001:62000)+2002*i;
% faces between the loadpaths
f(:,i+80000)=[((i-.5)*2002)+1,((i)*2002)+1,(i-.5)*2002+20029];
f(:,i+80009)=[((i)*2002)+20029,((i)*2002)+1,(i-.5)*2002+20029];
f(:,i+80018)=f(:,i+80000)+1000;
f(:,i+80027)=f(:,i+80009)+1000;
end
f=f+4; % adjusting point indicies to reflect the first 4 points being used for grip stock
% generating grip stock and loadpath attachment points
f(:,80037)=[1,2,3]; % bottom face -x gs -x,-y triangle (third angle proj.)
f(:,80038)=[2,3,4]; % bottom face -x gs +x,+y triangle
f(:,80039)=[1,2,20029]; % left face -x gs -y,-z triangle
f(:,80040)=[1,3,20029]; % front face -x gs -x,-z triangle
f(:,80041)=[2,20030,20029]; % left face -x gs, +y,+z triangle
f(:,80042)=[2,4,20030]; % back face -x gs, -x,-z triangle
f(:,80043)=[4,20032,20030]; % back face -x gs, +x,+z triangle
f(:,80044)=[3,20031,20029]; % front face -x gs, +x,+z triangle
f(:,80045:80046)=[f(:,80037),f(:,80038)]+20028; % top face +x gs, both triangles
f(:,80047:80056)=f(:,80037:80046)+20024; % +x gs, all triangles
% attaching grip stock to first and last loadpaths.
f(:,80057)=[4,5,20032];
f(:,80058)=[5,20032,20033];
f(:,80059)=[20028,1005,21033];
f(:,80060)=[20028,21033,40056];
f(:,80061)=[3,19024,39052];
f(:,80062)=[3,20031,39052];
f(:,80063)=[20024,20027,40055];
f(:,80064)=[40055,40051,20024];
%% converting to triangulation object and stl
tr=triangulation(f’,db’);
%trisurf(tr)
axis ‘equal’
stlwrite(tr, ‘stl_test.stl’)
%patch(‘Faces’,f(:,:)’,’Vertices’,db’,’facecol’,[1,0,0],’edgecol’,’k’);I get an output file looking like the following picture when trying to export my triangulation object as an stl. the yellow represents valid faces and the red corresponds to missing faces. The section of code where I generate the face connectivity and convert to a triangulation object and subsequently an stl file.
Each "loadpath" (wiggly strand connecting one rectangle to the other) is defined in 2-d by a set of 2 1001 point curves, and in 3-d by a simple upwards translation of those curves. The matrix containing my points starts with 4 points defining the -z corners of the -x grip stock (rectangular section), followed by the +y and -y curves defining each of the loadpaths on the -z face of the object, then the 4 points defining the -z corners of the +x grip stock, the 4 points defining the +z corners of the -x grip stock, the upper loadpaths, and finally the 4 corners defining the +z corners of the +x grip stock.
% Generating tringular tiling of the loadpaths
f=zeros(3,2001*10*4);
for i=1:1000 % first loadpath
f(:,i)=[i,i+1,1001+i]; %y+ layer of triangles on bottom face
f(:,1000+i)=[i+1,1001+i,1002+i]; %y- layer of triangles on bottom face
f(:,20000+i)=[i,i+1,20028+i]; %z- layer of triangles on y+ face
f(:,21000+i)=[i+1,20028+i,20029+i]; %z+ layer of tringles on y+ face
f(:,40000+i)=[1001+i,1002+i,21029+i];
f(:,41000+i)=[1002+i,21029+i,21030+i];
f(:,60000+i)=[20028+i,20029+i,21029+i];
f(:,61000+i)=[20029+i,21029+i,21030+i];
end
for i=1:9 % loadpaths 2-10
f(:,((2000*i)+1):((2000*(i+1))))=f(:,1:2000)+2002*i;
f(:,((2000*i)+20000+1):(2000*(i+1)+20000))=f(:,20001:22000)+2002*i;
f(:,((2000*i)+40000+1):(2000*(i+1)+40000))=f(:,40001:42000)+2002*i;
f(:,((2000*i)+60000+1):(2000*(i+1)+60000))=f(:,60001:62000)+2002*i;
% faces between the loadpaths
f(:,i+80000)=[((i-.5)*2002)+1,((i)*2002)+1,(i-.5)*2002+20029];
f(:,i+80009)=[((i)*2002)+20029,((i)*2002)+1,(i-.5)*2002+20029];
f(:,i+80018)=f(:,i+80000)+1000;
f(:,i+80027)=f(:,i+80009)+1000;
end
f=f+4; % adjusting point indicies to reflect the first 4 points being used for grip stock
% generating grip stock and loadpath attachment points
f(:,80037)=[1,2,3]; % bottom face -x gs -x,-y triangle (third angle proj.)
f(:,80038)=[2,3,4]; % bottom face -x gs +x,+y triangle
f(:,80039)=[1,2,20029]; % left face -x gs -y,-z triangle
f(:,80040)=[1,3,20029]; % front face -x gs -x,-z triangle
f(:,80041)=[2,20030,20029]; % left face -x gs, +y,+z triangle
f(:,80042)=[2,4,20030]; % back face -x gs, -x,-z triangle
f(:,80043)=[4,20032,20030]; % back face -x gs, +x,+z triangle
f(:,80044)=[3,20031,20029]; % front face -x gs, +x,+z triangle
f(:,80045:80046)=[f(:,80037),f(:,80038)]+20028; % top face +x gs, both triangles
f(:,80047:80056)=f(:,80037:80046)+20024; % +x gs, all triangles
% attaching grip stock to first and last loadpaths.
f(:,80057)=[4,5,20032];
f(:,80058)=[5,20032,20033];
f(:,80059)=[20028,1005,21033];
f(:,80060)=[20028,21033,40056];
f(:,80061)=[3,19024,39052];
f(:,80062)=[3,20031,39052];
f(:,80063)=[20024,20027,40055];
f(:,80064)=[40055,40051,20024];
%% converting to triangulation object and stl
tr=triangulation(f’,db’);
%trisurf(tr)
axis ‘equal’
stlwrite(tr, ‘stl_test.stl’)
%patch(‘Faces’,f(:,:)’,’Vertices’,db’,’facecol’,[1,0,0],’edgecol’,’k’); I get an output file looking like the following picture when trying to export my triangulation object as an stl. the yellow represents valid faces and the red corresponds to missing faces. The section of code where I generate the face connectivity and convert to a triangulation object and subsequently an stl file.
Each "loadpath" (wiggly strand connecting one rectangle to the other) is defined in 2-d by a set of 2 1001 point curves, and in 3-d by a simple upwards translation of those curves. The matrix containing my points starts with 4 points defining the -z corners of the -x grip stock (rectangular section), followed by the +y and -y curves defining each of the loadpaths on the -z face of the object, then the 4 points defining the -z corners of the +x grip stock, the 4 points defining the +z corners of the -x grip stock, the upper loadpaths, and finally the 4 corners defining the +z corners of the +x grip stock.
% Generating tringular tiling of the loadpaths
f=zeros(3,2001*10*4);
for i=1:1000 % first loadpath
f(:,i)=[i,i+1,1001+i]; %y+ layer of triangles on bottom face
f(:,1000+i)=[i+1,1001+i,1002+i]; %y- layer of triangles on bottom face
f(:,20000+i)=[i,i+1,20028+i]; %z- layer of triangles on y+ face
f(:,21000+i)=[i+1,20028+i,20029+i]; %z+ layer of tringles on y+ face
f(:,40000+i)=[1001+i,1002+i,21029+i];
f(:,41000+i)=[1002+i,21029+i,21030+i];
f(:,60000+i)=[20028+i,20029+i,21029+i];
f(:,61000+i)=[20029+i,21029+i,21030+i];
end
for i=1:9 % loadpaths 2-10
f(:,((2000*i)+1):((2000*(i+1))))=f(:,1:2000)+2002*i;
f(:,((2000*i)+20000+1):(2000*(i+1)+20000))=f(:,20001:22000)+2002*i;
f(:,((2000*i)+40000+1):(2000*(i+1)+40000))=f(:,40001:42000)+2002*i;
f(:,((2000*i)+60000+1):(2000*(i+1)+60000))=f(:,60001:62000)+2002*i;
% faces between the loadpaths
f(:,i+80000)=[((i-.5)*2002)+1,((i)*2002)+1,(i-.5)*2002+20029];
f(:,i+80009)=[((i)*2002)+20029,((i)*2002)+1,(i-.5)*2002+20029];
f(:,i+80018)=f(:,i+80000)+1000;
f(:,i+80027)=f(:,i+80009)+1000;
end
f=f+4; % adjusting point indicies to reflect the first 4 points being used for grip stock
% generating grip stock and loadpath attachment points
f(:,80037)=[1,2,3]; % bottom face -x gs -x,-y triangle (third angle proj.)
f(:,80038)=[2,3,4]; % bottom face -x gs +x,+y triangle
f(:,80039)=[1,2,20029]; % left face -x gs -y,-z triangle
f(:,80040)=[1,3,20029]; % front face -x gs -x,-z triangle
f(:,80041)=[2,20030,20029]; % left face -x gs, +y,+z triangle
f(:,80042)=[2,4,20030]; % back face -x gs, -x,-z triangle
f(:,80043)=[4,20032,20030]; % back face -x gs, +x,+z triangle
f(:,80044)=[3,20031,20029]; % front face -x gs, +x,+z triangle
f(:,80045:80046)=[f(:,80037),f(:,80038)]+20028; % top face +x gs, both triangles
f(:,80047:80056)=f(:,80037:80046)+20024; % +x gs, all triangles
% attaching grip stock to first and last loadpaths.
f(:,80057)=[4,5,20032];
f(:,80058)=[5,20032,20033];
f(:,80059)=[20028,1005,21033];
f(:,80060)=[20028,21033,40056];
f(:,80061)=[3,19024,39052];
f(:,80062)=[3,20031,39052];
f(:,80063)=[20024,20027,40055];
f(:,80064)=[40055,40051,20024];
%% converting to triangulation object and stl
tr=triangulation(f’,db’);
%trisurf(tr)
axis ‘equal’
stlwrite(tr, ‘stl_test.stl’)
%patch(‘Faces’,f(:,:)’,’Vertices’,db’,’facecol’,[1,0,0],’edgecol’,’k’); stl, triangulation MATLAB Answers — New Questions









