Merge isocap and isosurf to get one surface

19 visualizzazioni (ultimi 30 giorni)
Dear Colleagues,
I having an issue with merging surfaces. I have a function f defined below for which I want to generate a volume enclosed by the isosurface and the isocap. I wish to merge these two surfaces into one surface that I want to extract later as stl file using stlwrite.
is there a way to do so ?
f = @(x,y,z) cos(2.*pi.*y).*sin(2.*pi.*x)+cos(2.*pi.*z);
O = 0:.05:1;
[x,y,z] = meshgrid(O);
v = f(x,y,z);
p1 = isosurface(x,y,z,v,0.2);
p2 = isocaps(x,y,z,v,0.2);

Risposta accettata

Paulo GOMES
Paulo GOMES il 18 Dic 2018
I found that this is a convinient solution.
for example you have the faces and vertices of an isosurface:
[f,v] = isosurface(x,y,z,Gyroid);
and the faces and vertices of an isocaps
[f2,v2,c] = isocaps(x,y,z,Gyroid);
then you can merge the faces and vertices together. Careful on how to merge the faces together, you need to send the vector pointer to the correct position of the vertices, otherwise you will send the pointer to the wrong vertice pointer - for this reason +length(v(:,1)) is added.
f3 = [f ; f2+length(v(:,1))];
v3 = [v ; v2];
face f3 and vertice v3 have the merged geometry!
Now if you want to save the file as stl you can write the following line
stlwrite('file_name.stl',f3,v3);
If you understant the example I gave, it is pretty straight forward to solve your problem!
Source:
min 26~29
  2 Commenti
Jesus Barney
Jesus Barney il 10 Mar 2020
Hello Paulo,
I tried exactly the above code:
f = @(x,y,z) cos(2.*pi.*y).*sin(2.*pi.*x)+cos(2.*pi.*z);
O = 0:.05:1;
[x,y,z] = meshgrid(O);
v = f(x,y,z);
[f,v] = isosurface(x,y,z,v,0.2);
stlwrite('file_name.stl',f,v);
and I get the error "Input argument must be a triangulation object." What am I doing wrong?
Ryan
Ryan il 18 Mar 2020
I have experienced this error also. My solution was to download the version of stlwrite written by Sven (avaliable here) and place it into the working directory or Matlab path.

Accedi per commentare.

Più risposte (1)

Oraib Al-Ketan
Oraib Al-Ketan il 23 Ago 2019
Modificato: Oraib Al-Ketan il 23 Ago 2019
Thank you very much Palo, your answer solved my problem perfectly.

Community Treasure Hunt

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

Start Hunting!

Translated by