How could I generate several ellipsoids in a single stl file

I try to generate stl file of single ellipsoid mainly by following steps:
  1. Input ellipsoid parameters via ''ellipsoid'' function.
  2. Create surface and convert to patch sturcture via ''surf2patch''
  3. Extract faces and vertices in patch sturcture.
  4. Build triangulation and correspond alphaShape
  5. Extract boundary faces of alphaShape and establish an new set of sriangulation.
  6. Export stl file via ''stlwrite'' function.
Hwoever, now I would like to export a stl file which contains several ellipsoids without overlapping.
The first step for me is to generate two ellipsoids in one stl file.
The second ellipsoid is generated and plotted with the first ellipsoid in the same figure.
But I do not know how to export them in the same stl file.
Would anyone gives me some hints or suggestions?
Thanks a lot.
Attached is the code.
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 ellipsoid
%input the properties of ellipsoid by ''ellipsoid'' function
[x1, y1, z1] = ellipsoid(7,7,7,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 one figure
hold on
plot(sha)
plot(sha1)
%export stl
%stlwrite(tr_c,'two_ell.stl')
I think I sould probably focus on ''How to merge two sets of triangulation in single set'' or ''How to creat an alphaShape contains several objects'', but I don't know how could I do so.
Sincerely and merry christmas.

5 commentaires

Daniel Chou
Daniel Chou le 25 Déc 2020
Modifié(e) : Daniel Chou le 25 Déc 2020
I solved the problem, inspired by following link:
The big picture of flow for generate single ellipsoid is
  1. Input ellipsoid parameters via ''ellipsoid'' function.
  2. Create surface and convert to patch sturcture via ''surf2patch''
  3. Extract faces and vertices in patch sturcture.
  4. Build triangulation and correspond alphaShape
  5. Extract boundary faces of alphaShape and establish an new set of sriangulation.
  6. 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
  1. Input ellipsoid parameters via ''ellipsoid'' function for each ellipsoid.
  2. Create surface and convert to patch sturcture via ''surf2patch'' for each ellipsoid.
  3. Extract faces and vertices in patch sturcture for each ellipsoid.
  4. Build triangulation and correspond alphaShape for each ellipsoid.
  5. Extract boundary faces of alphaShape and establish an new set of sriangulation for each ellipsoid.
  6. Create a structure to storage faces and vertices of each ellipsoid.
  7. Establish the triangulation of all ellipsoids which storaged in step 6.
  8. 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
Thanks a lot for sharing your answer. That was exactly what I was looking for.
Daniel Chou
Daniel Chou le 13 Juil 2021
Modifié(e) : Daniel Chou le 13 Juil 2021
@Jakob You're welcome. Thanks for refering it. It was encouraging for me :)
I have a similar problem, I'm generating randomly distributed spheres and now I want to export this geometry.
You're code works perfectly fine with spheres, but when I added a third sphere I got an error. (Same if I added a third ellipsoid to your code.)
"Warning: Duplicate data points have been detected and removed." --> In the line with sha2 = alphaShape(tr2.Points);
After that a *.stl-file is created, but it only contains two spheres and the third one is missing. The spheres don't overlap, I don't understand why matlab finds duplicate data points. I'm really confused.
How can I adapt this code for 3 or any number of spheres/ellipsoids? Can you please help me?
@Ju Lia have you solved your problem?
In case you want me to help you more
My email: dchou9@gatech.edu
Sincerely

Connectez-vous pour commenter.

Réponses (0)

Catégories

Commenté :

le 15 Juin 2022

Community Treasure Hunt

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

Start Hunting!

Translated by