How could I generate several ellipsoids in a single stl file

8 Ansichten (letzte 30 Tage)
Daniel Chou
Daniel Chou am 24 Dez. 2020
Kommentiert: Daniel Chou am 15 Jun. 2022
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 Kommentare
Ju Lia
Ju Lia am 15 Jun. 2022
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?
Daniel Chou
Daniel Chou am 15 Jun. 2022
@Ju Lia have you solved your problem?
In case you want me to help you more
My email: dchou9@gatech.edu
Sincerely

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Lighting, Transparency, and Shading finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by