# Merge isocap and isosurf to get one surface

16 views (last 30 days)
oraib alketan on 18 Jan 2018
Commented: Ryan on 18 Mar 2020
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);

Paulo GOMES on 18 Dec 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

Jesus Barney on 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 on 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.