I solved the problem, inspired by following link:
The big picture of flow for generate single ellipsoid is
- Input ellipsoid parameters via ''ellipsoid'' function.
- Create surface and convert to patch sturcture via ''surf2patch''
- Extract faces and vertices in patch sturcture.
- Build triangulation and correspond alphaShape
- Extract boundary faces of alphaShape and establish an new set of sriangulation.
- Export stl file via ''stlwrite'' function.
For multiple ellipsoids, just creat an extra structure in step 5 to storage the faces and vertices of all ellipsoids, then create triangulation for new storage structure. Eventially both ellipsoid could be generated in one single stl file.
The comprehensive work flow of multiple ellipsoids will then be
- Input ellipsoid parameters via ''ellipsoid'' function for each ellipsoid.
- Create surface and convert to patch sturcture via ''surf2patch'' for each ellipsoid.
- Extract faces and vertices in patch sturcture for each ellipsoid.
- Build triangulation and correspond alphaShape for each ellipsoid.
- Extract boundary faces of alphaShape and establish an new set of sriangulation for each ellipsoid.
- Create a structure to storage faces and vertices of each ellipsoid.
- Establish the triangulation of all ellipsoids which storaged in step 6.
- Export stl file via ''stlwrite'' function based on the triangulation in step 7.
The code will be
clear
clc
close all
%input the properties of ellipsoid by ''ellipsoid'' function
[x, y, z] = ellipsoid(1,1,1,5,3,3);
%Convert the ellipsoid to surface via ''surf''
s=surf(x,y,z)
%from surface to patch: generate the faces and vertices
p=surf2patch(s)
%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
%Extract boundary face of alphaShape
[F,P]=boundaryFacets(sha)
%New set of triangulation
Newtr=triangulation(F,P)
%Second ell
%input the properties of ellipsoid by ''ellipsoid'' function
[x1, y1, z1] = ellipsoid(5,5,5,5,3,3);
%Convert the ellipsoid to surface via ''surf''
s1=surf(x1,y1,z1)
%from surface to patch: generate the faces and vertices
p1=surf2patch(s1)
%Extract faces and vertices from structure p
pf1=p1.faces
pv1=p1.vertices
tr1=triangulation(pf1,pv1)
sha1=alphaShape(tr1.Points)
%Using larger sha.Alpha to imprive the quality of mesh
sha1.Alpha=5
%Extract boundary face of alphaShape
[F1,P1]=boundaryFacets(sha1)
%New set of triangulation
Newtr1=triangulation(F1,P1)
%plotting both ellipsoids in figure
hold on
plot(sha)
plot(sha1)
%Key point of this problem
%creat a structure to store the faces and vertices of ellipsoid
nv=length(P);
fv_combined.vertices=[P;P1]
fv_combined.faces=[F; F1+nv]
contri=triangulation(fv_combined.faces,fv_combined.vertices)
stlwrite(contri,'two_ell.stl')
The result file in meshmixer is provided as follow:
Some extra works are described below (only for reference and record of my self-learning):
As further trying (to make the script simpler), I storage the faces of vertices in step 2 as well, but in this manner I do not got desired result.
So just for reference.
I hope this helps when someone has similar question.
Sincerely