How to generate a .stl file starting from a 3d figure
조회 수: 145 (최근 30일)
이전 댓글 표시
Hi everyone,
I'm dealing with the following problem:
I need to generate an .stl of the 3d figure that I have achieved with the following code (the one shown here below). I saw that a possible oprion is to use the function "surf2stl" however I'm unable to implement its inputs.
Does anyone know how to write the inputs of this function?
Any other suggestions are really appreciate.
Thanks for the attenction.
Vcub=[0 0 0; 1 0 0; 0 1 0; 0 0 1;1 1 1; 0 1 1; 1 0 1; 1 1 0];
%Vcub(:,2)=2*Vcub(:,2);
N=100;
seeds=1.5*rand(N,3)-0.25;
[Ver,Cel,C_tst]=voronoi3d_cuboid(seeds,Vcub);
figure
hold on
axis('equal')
view([-36 27])
for k = 1:length(Cel)
if ~isempty(Cel{k})
col= rand(1,3);
Vk = Ver(Cel{k},:);
Fk = convhull(Vk);
if exist('mergeCoplanarFaces.m','file')==2
[Vk, Fk] = mergeCoplanarFaces(Vk, Fk);
for i=1:length(Fk)
patch('Vertices',Vk,'Faces',Fk{i},'FaceColor',col,'FaceAlpha',0,'LineWidth',3,'EdgeAlpha',1,'EdgeColor','k')
end
else
trisurf(Fk,Vk(:,1),Vk(:,2),Vk(:,3),'FaceColor',col, ...
'FaceAlpha', 1,'EdgeAlpha',1,'EdgeColor','k');
end
end
end
xlabel('X');
ylabel('Y');
zlabel('Z');
채택된 답변
Arpit Bhatia
2020년 10월 27일
Hi Tonino,
You need to download the stlwrite.m file from the following link: https://in.mathworks.com/matlabcentral/fileexchange/20922-stlwrite-write-ascii-or-binary-stl-files
(Please note that this file has not been created by or maintained by MathWorks)
With the stlwrite.m file in the same folder as the file with the above code, add the following command to the end of your code to generate the required stl file.
stlwrite('mytriangulation.stl',struct('faces', Fk, 'vertices',Vk));
The reason you were earlier facing the error “Input argument must be a triangulation object” is that you were calling the default MATLAB stlwrite function which requires a triangulation as an input argument. To use that function, you will need to first create a triangulation as specified below.
TO = triangulation(Fk,Vk(:,1),Vk(:,2),Vk(:,3));
trisurf(TO,'FaceColor',col, ...
'FaceAlpha', 1,'EdgeAlpha',1,'EdgeColor','k');
stlwrite(TO,'test.stl')
댓글 수: 4
Abdelmadjid Boualleg
2021년 3월 16일
편집: Abdelmadjid Boualleg
2021년 3월 16일
Hi Arpit Bhatia
Thank you for your help above regarding the provided information about Stlwrite for Voronoi 3D, but when I used that function, it gives me Stl file with triangulation edges, not Voronoi edges as you can see in the attached picture, therefore I kindly ask you to help me for getting the Stl of Voronoi not triangulation. Thank you very much in advance.
Akshay Kumar Pakala
2022년 3월 10일
Hey Arpita Bhatia
I would like to know if the stlwrite function works to create the entire voronoi cuboid if i store the Vk and Fk matrices at every loop into 2 seperate cells or in two different multi-dimensional dimensional matrix respectively?
Thank you
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!