- Official MATALB one: https://uk.mathworks.com/help/matlab/ref/stlwrite.html
- One on the FEX: https://uk.mathworks.com/matlabcentral/fileexchange/20922-stlwrite-write-ascii-or-binary-stl-files
stl export for geometry from pointcloud/array
7 ビュー (過去 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?
0 件のコメント
採用された回答
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
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!