How to export stl file from triangles.

8 次查看(过去 30 天)
Nicolas Rogalski
Nicolas Rogalski 2019-5-26
回答: DGM 2025-10-7,21:16
Hello,
I want to export a stl file from triangulated points. The outputs of my code are the points id contained in triangles (nx3 array) and the outwards normals of trianglesm (nx3 array).
I tried the functions stlwrite or surf2stl but the results are not good.
Thank you for your help!

回答(1 个)

DGM
DGM 2025-10-7,21:16
If you have a list of vertices (coordinate positions), and a list of triangular faces (indices into the vertex list), then you can just write that directly to an STL. You don't need the normals. The encoder will calculate them internally.
Since R2018b, MATLAB has built-in STL tools. You don't need to download anything. stlread() stlwrite()
For legacy versions needing third-party tools, I'd strongly recommend these tools. This explains why.
FEX surf2stl() works on gridded data, not on triangulations. If you're using "stlwrite", then you're probably using FEX #20922, and probably using it by feeding it XYZ coordinate data in the same way you had used surf2stl(), which would be the wrong way to use it for the same reason.
That said, there are any number of ways to represent mesh triangles other than as references to a vertex list. If it's stored in a direct manner, then obviously one would need to know how it was arranged in order to put it into a usable format.

Community Treasure Hunt

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

Start Hunting!

Translated by