How could I create stl file based on the ellipsoid command?

6 visualizaciones (últimos 30 días)
Daniel Chou
Daniel Chou el 21 de Dic. de 2020
Editada: DGM el 12 de Jul. de 2025
I try several methods to write an stl file based on the ellipsoid geometry.
But I haven't find way to successfully do it.
Following is my code
clear
clc
close all
[x, y, z] = ellipsoid(0,0,0,5.9,3.25,3.25,30);
s=surf(x,y,z)
p=surf2patch(s)
%Extract faces and vertices from structure p
pf=p.faces
pv=p.vertices
tr=triangulation(pf,pv)
stlwrite(tr,'ell.stl')
The message ''Tetrahedron triangulation is not supported.'' appears, I know I could use ''boundaryFacets'' command to solve this problem, but I don't know how to create an alphaShape of ellipsoid.
Could anyone gives me a hint?

Respuesta aceptada

Aditya Patil
Aditya Patil el 24 de Dic. de 2020
stlwrite only support triangles.
You can get the alphaShape of ellipsoid using the alphaShape function.
shp = alphaShape(tr.Points)
There is also the freeBoundary function.
[F,P] = freeBoundary(tr)
trNew = triangulation(F,P)
stlwrite(trNew, "freeboundary.stl")
  2 comentarios
Daniel Chou
Daniel Chou el 24 de Dic. de 2020
Editada: Daniel Chou el 24 de Dic. de 2020
Dear @Aditya Patil
I sincerely appreciate for your assistance.
You save me from this haha.
Before viewing your suggestion, I already used the freeboundary method to create the stl file. However, the mesh quality is a disaster, I'm still trying to figure out how to solve it.
After reading your hint I try to modify my code as follow,
clear
clc
close all
%input the properties of ellipsoid by ''ellipsoid'' function
[x, y, z] = ellipsoid(1,1,1,5.9,3.25,3.25,30,5);
%Convert the ellipsoid to surface via ''surf''
s=surf(x,y,z)
%from surface to patch: generate the faces and vertices
p=surf2patch(x,y,z)
%Extract faces and vertices from structure p
pf=p.faces
pv=p.vertices
tr=triangulation(pf,pv)
sha=alphaShape(tr.Points)
%Using larger sha.Alpha to imprive the quality of mesh
sha.Alpha=5
plot(sha)
%Extract boundary face of alphaShape
[F,P]=boundaryFacets(sha)
%New set of triangulation
Newtr=triangulation(F,P)
%Export stl file
stlwrite(Newtr, "ell_3.stl")
I got an adorable ellipsoid stl file with steady mesh quality, which allows me to do re-meshing work in meshmixer and further model manipulation in solidworks.
Thank you very much again!!
Sincerely yours
Daniel Chou
DGM
DGM el 12 de Jul. de 2025
Editada: DGM el 12 de Jul. de 2025
It's not necessary to use alphashape and risk complications with maintaining non-convex features. You need a triangular surface mesh. By default, surf2patch() returns a quadrilateral surface mesh, not a tetrahedral volume mesh. From the perspective of stlwrite(), the difference is ambiguous. Elements with four vertices might be quads, or they might be tetrahedrons (really, I suppose they tend to be tetrahedrons either way, since surf "quads" aren't always planar). Regardless of what stlwrite() assumes they're supposed to be, a standard STL doesn't contain either, so the difference is moot.
If you want triangles, ask for triangles.
[x, y, z] = ellipsoid(0,0,0,5.9,3.25,3.25,30);
s=surf(x,y,z);
p=surf2patch(s,'triangles');
%Extract faces and vertices from structure p
pf=p.faces;
pv=p.vertices;
tr=triangulation(pf,pv) % elements have three vertices, not four
tr =
triangulation with properties: Points: [961×3 double] ConnectivityList: [1800×3 double]
stlwrite(tr,'ell.stl') % no error

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Bounding Regions en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by