Filling area between two planes in 3d plot

33 visualizzazioni (ultimi 30 giorni)
I'm trying to more or less plot an amorphous blob on a 3d plot. I know the top, and I know the bottom. Is there an easy way to fill the space between? For example, if I have
hold on
surf(peaks + 5)
hold off
How could I connect the two planes so it's like a volume?
Thank you so much for your time

Risposta accettata

Mike Garrity
Mike Garrity il 4 Set 2015
The isosurface approach that Tim suggested is possible. Here's an example of how you'd do that. It's a bit involved and it uses quite a bit of memory:
%%Start with 2 surfaces
nx = 25;
ny = 25;
nz = 25;
[x,y] = meshgrid(linspace(-2,2,nx),linspace(-2,2,ny));
z1 = peaks(x,y);
z2 = peaks(x,y) + 5;
hold on
%%Create 3D grid containing distance to closest surface
[y3,x3,z3] = ndgrid(linspace(-2,2,ny),linspace(-2,2,nx),linspace(-10,15,nz));
v = zeros(size(z3));
for r=1:ny
for c=1:nx
for s=1:nz
d1 = z3(r,c,s) - z1(r,c);
d2 = z2(r,c) - z3(r,c,s);
if d1 < 0
v3(r,c,s) = d1;
elseif d2 < 0
v3(r,c,s) = d2;
v3(r,c,s) = min(d1,d2);
%%Create isosurface
p = [patch(isosurface(x3,y3,z3,v3,0)), ...
camlight right
You need both isosurface and isocaps there. The isosurface command creates the parts inside the volume (the same parts surf created) while isocaps creates the parts along the boundary. You can also combine isocaps from that example with your surface objects like this:
hold on
  3 Commenti
Mike Garrity
Mike Garrity il 4 Set 2015
Modificato: Mike Garrity il 4 Set 2015
If you are going to go the isocaps route, then you're probably going to need to worry about time/memory performance tradeoffs. For example, in some cases it will probably be much better to get rid of those nested for loops and use extra temporary variables instead.
[y3,x3,z3] = ndgrid(linspace(-2,2,ny), ...
linspace(-2,2,nx), ...
v3 = min(z3 - repmat(z1,[1 1 nz]), ...
repmat(z2,[1 1 nz]) - z3);
I think that this would take a lot less time, when you have enough memory for those expanded copies of z1 & z2.
But if you really end up against the performance wall, then Tim Jackman's other suggestion about creating the patches yourself will probably be the way to go.
Ksenia Shukhin
Ksenia Shukhin il 31 Mag 2022
Hi Mike!
I have used your code for creation a 3d object, thank you a lot. But now the question is how to create stl file from this. Maybe you can help?

Accedi per commentare.

Più risposte (1)

Tim Jackman
Tim Jackman il 3 Set 2015
One option would be to create an isosurface, but to do that you would need to convert your data into a 3-D gridded data. This link has some more information and a couple examples to follow:
Based on the example you provided, and quick way to fill the space in between the two surfaces would be to apply a patch. For example:
hold on
surf(peaks + 5)
hold off
Now place a polygon along one edge by supplying the X, Y, and Z coordinates along with the color you want:
You can get more information on the patch objects here:


Scopri di più su Lighting, Transparency, and Shading in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by