stl export for geometry from pointcloud/array

6 次查看(过去 30 天)
Hello,
I want to export a geometry to stl. Here I used a very simple example but it's comparable with my application since I have a geometry defined by a pointcloud.
d = [0 1];
[x,y,z] = meshgrid(d,d,d); % a cube
x = [x(:);0];
y = [y(:);0];
z = [z(:);0];
DT = delaunayTriangulation(x,y,z);
tetramesh(DT);
camorbit(20,0)
I found in a forum that you could use this expression:
stlwrite('Quader.stl',DT.ConnectivityList,DT.Points);
but it didn't work and according to the Matlab website, stlwrite has to have the following structure:
stlwrite(TR,filename)
where TR is a triangulation object. Following this logic, I tried to implement
stlwrite(DT,'Quader.stl');
but I get the error: "Tetrahedron triangulation is not supported."
The following version "works" in a sense that I get an export but it's just 2D instead of 3D
T = delaunay(x,y);
tri = triangulation(T,x,y,z);
stlwrite(tri,'Quader.stl');
Could you please tell me, where I went wrong and what I have to do to solve this?

采纳的回答

Michael Croucher
Michael Croucher 2020-10-13
I should start this answer with 'I have no idea what I'm doing here'. I found your question interesting and have had a go at it with a combination of googling and experimentation. As such, this may be a terrible way to proceed but I seem to have got somewhere
The first complication is that there are at least two stlwrite functions:
. I think that your forum posts were referring to the FEX version which is older. For what follows, I use the FEX version
d = [0 1];
[x,y,z] = meshgrid(d,d,d); % a cube
x = [x(:);0];
y = [y(:);0];
z = [z(:);0];
stlwrite('Quader.stl',boundary(x,y,z),[x,y,z],'mode','ascii');
I used a free stl viewer to look at the result and the wireframe returned was
I chose ASCII output so we can look at it. Probably want to use binary output (the default) for big files. The contents of the file are
solid Created by stlwrite.m 13-Oct-2020 16:32:19
facet normal 0.0000000E+00 0.0000000E+00 -1.0000000E+00
outer loop
vertex 0.0000000E+00 0.0000000E+00 0.0000000E+00
vertex 0.0000000E+00 1.0000000E+00 0.0000000E+00
vertex 1.0000000E+00 0.0000000E+00 0.0000000E+00
endloop
endfacet
facet normal 0.0000000E+00 -1.0000000E+00 0.0000000E+00
outer loop
vertex 0.0000000E+00 0.0000000E+00 1.0000000E+00
vertex 0.0000000E+00 0.0000000E+00 0.0000000E+00
vertex 1.0000000E+00 0.0000000E+00 0.0000000E+00
endloop
endfacet
facet normal -1.0000000E+00 0.0000000E+00 0.0000000E+00
outer loop
vertex 0.0000000E+00 0.0000000E+00 1.0000000E+00
vertex 0.0000000E+00 1.0000000E+00 0.0000000E+00
vertex 0.0000000E+00 0.0000000E+00 0.0000000E+00
endloop
endfacet
facet normal -1.0000000E+00 -0.0000000E+00 -0.0000000E+00
outer loop
vertex 0.0000000E+00 1.0000000E+00 1.0000000E+00
vertex 0.0000000E+00 1.0000000E+00 0.0000000E+00
vertex 0.0000000E+00 0.0000000E+00 1.0000000E+00
endloop
endfacet
facet normal -0.0000000E+00 -1.0000000E+00 -0.0000000E+00
outer loop
vertex 1.0000000E+00 0.0000000E+00 1.0000000E+00
vertex 0.0000000E+00 0.0000000E+00 1.0000000E+00
vertex 1.0000000E+00 0.0000000E+00 0.0000000E+00
endloop
endfacet
facet normal 0.0000000E+00 0.0000000E+00 1.0000000E+00
outer loop
vertex 0.0000000E+00 1.0000000E+00 1.0000000E+00
vertex 0.0000000E+00 0.0000000E+00 1.0000000E+00
vertex 1.0000000E+00 0.0000000E+00 1.0000000E+00
endloop
endfacet
facet normal 1.0000000E+00 0.0000000E+00 0.0000000E+00
outer loop
vertex 1.0000000E+00 1.0000000E+00 0.0000000E+00
vertex 1.0000000E+00 0.0000000E+00 1.0000000E+00
vertex 1.0000000E+00 0.0000000E+00 0.0000000E+00
endloop
endfacet
facet normal 0.0000000E+00 0.0000000E+00 -1.0000000E+00
outer loop
vertex 0.0000000E+00 1.0000000E+00 0.0000000E+00
vertex 1.0000000E+00 1.0000000E+00 0.0000000E+00
vertex 1.0000000E+00 0.0000000E+00 0.0000000E+00
endloop
endfacet
facet normal 0.0000000E+00 1.0000000E+00 0.0000000E+00
outer loop
vertex 0.0000000E+00 1.0000000E+00 1.0000000E+00
vertex 1.0000000E+00 1.0000000E+00 0.0000000E+00
vertex 0.0000000E+00 1.0000000E+00 0.0000000E+00
endloop
endfacet
facet normal 1.0000000E+00 0.0000000E+00 0.0000000E+00
outer loop
vertex 1.0000000E+00 1.0000000E+00 1.0000000E+00
vertex 1.0000000E+00 0.0000000E+00 1.0000000E+00
vertex 1.0000000E+00 1.0000000E+00 0.0000000E+00
endloop
endfacet
facet normal -0.0000000E+00 1.0000000E+00 0.0000000E+00
outer loop
vertex 0.0000000E+00 1.0000000E+00 1.0000000E+00
vertex 1.0000000E+00 1.0000000E+00 1.0000000E+00
vertex 1.0000000E+00 1.0000000E+00 0.0000000E+00
endloop
endfacet
facet normal -0.0000000E+00 0.0000000E+00 1.0000000E+00
outer loop
vertex 0.0000000E+00 1.0000000E+00 1.0000000E+00
vertex 1.0000000E+00 0.0000000E+00 1.0000000E+00
vertex 1.0000000E+00 1.0000000E+00 1.0000000E+00
endloop
endfacet
endsolid Created by stlwrite.m 13-Oct-2020 16:32:19
  1 个评论
Kim
Kim 2020-10-14
Thank you very much, Matlab took indeed the build-in function 'stlwrite'. If I call specifically the function of the FEX toolbox, it works just fine.

请先登录,再进行评论。

更多回答(0 个)

标签

产品


版本

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by