# Filling between two 3D surfaces

I know it is possible to create a filling in between two curves on a 2D plot, but is it possible to do the same in 3D?

My attempt like this:

Z1 := E^(-x^2) Cos[x^2 + y^2]
Z2 := 2 - x^2 - y^2

Plot3D[{Z1, Z2}, {x, -1, 1}, {y, -1, 1}, AspectRatio -> 1,
ViewPoint -> {4, 1, 1}, Filling -> Top, FillingStyle -> Opacity[0.9]]


yields the graph below:

Is there a way I can fill the graph between the two aforementioned 3D surfaces?

-
@IstvánZachar Thanks, it's fixed now... – Oliver Spryn Nov 20 '12 at 16:57
Yes, I do remember now: this is an old bug I've encountered earlier. Simpler version: Plot3D[{1, 2}, {x, 0, 1}, {y, 0, 1}, Filling -> {1 -> {2}}] Sadly, I don't know any workaround. – István Zachar Nov 20 '12 at 17:07
@IstvánZachar Just wondering... regarding the Plot3D[{1, 2}... what is the {1, 2} plotting, just 1 and 2 in three space? – Oliver Spryn Nov 20 '12 at 17:11
@IstvánZachar Your solution usually works for 2D plots, but doesn't seem to work for 3D. – VLC Nov 20 '12 at 17:13
should this be listed as a bug (given the comments and answers?) – Mike Honeychurch Nov 20 '12 at 20:46

How do you like this?

RegionPlot3D[
2 - x^2 - y^2 > z > E^(-x^2) Cos[x^2 + y^2], {x, -1, 1}, {y, -1,
1}, {z, -0.2, 2}, Mesh -> False, AspectRatio -> 1,
ViewPoint -> {4, 1, 1}, PlotStyle -> {LightBlue, Opacity[0.8]}]


-
I like it! +1 for simplicity! – Oliver Spryn Nov 21 '12 at 13:23

As far as I understand the documentation, the following should work:

f[x_, y_] = E^(-x^2) Cos[x^2 + y^2];
g[x_, y_] = 2 - x^2 - y^2;
pic = Plot3D[{f[x, y], g[x, y]}, {x, -1, 1}, {y, -1, 1},
AspectRatio -> 1, ViewPoint -> {4, 1, 1},
Filling -> {1 -> {2}}, FillingStyle -> Opacity[0.9]]


The fact that it doesn't looks like a bug to me. The following might be a reasonable workaround:

{{a, b}, {c, d}} = {{-1, 1}, {-1, 1}};
dx = (b - a)/80;
dy = (d - c)/80;
fillEdges = Graphics3D[{Opacity[0.9], EdgeForm[],
Polygon[Join[
Table[{
{x, c, f[x, c]}, {x + dx, c, f[x + dx, c]},
{x + dx, c, g[x + dx, c]}, {x, c, g[x, c]}},
{x, a, b - dx, dx}],
Table[Reverse@{
{x, d, f[x, d]}, {x + dx, d, f[x + dx, d]},
{x + dx, d, g[x + dx, d]}, {x, d, g[x, d]}},
{x, a, b - dx, dx}],
Table[{
{a, y, f[a, y]}, {a, y + dy, f[a, y + dy]},
{a, y + dy, g[a, y + dy]}, {a, y, g[a, y]}},
{y, c, d - dy, dy}],
Table[{
{b, y, f[b, y]}, {b, y + dy, f[b, y + dy]},
{b, y + dy, g[b, y + dy]}, {b, y, g[b, y]}},
{y, c, d - dy, dy}]
]]}];
Show[{pic, fillEdges}]


-

This is a rough solution that does what you're looking for:

Z1[x_, y_] := E^(-x^2) Cos[x^2 + y^2]
Z2[x_, y_] := 2 - x^2 - y^2

side1 = Join[Table[{-1, y, Z1[-1, y]}, {y, -1, 1, .1}],
Reverse[Table[{-1, y, Z2[-1, y]}, {y, -1, 1, .1}]]];
side2 = Join[Table[{1, y, Z1[1, y]}, {y, -1, 1, .1}],
Reverse[Table[{1, y, Z2[1, y]}, {y, -1, 1, .1}]]];
side3 = Join[Table[{x, -1, Z1[x, -1]}, {x, -1, 1, .1}],
Reverse[Table[{x, -1, Z2[x, -1]}, {x, -1, 1, .1}]]];
side4 = Join[Table[{x, 1, Z1[x, 1]}, {x, -1, 1, .1}],
Reverse[Table[{x, 1, Z2[x, 1]}, {x, -1, 1, .1}]]];

Show[
Plot3D[{Z1[x, y], Z2[x, y]}, {x, -1, 1}, {y, -1, 1},
AspectRatio -> 1, ViewPoint -> {4, 1, 1}],
Graphics3D[{Opacity[.9], Polygon[side1], Polygon[side2], Polygon[side3],
Polygon[side4]}]
]


-

I would suggest using ParametricPlot3D to draw the "filling" polygons:

Z1[x_, y_] := E^(-x^2) Cos[x^2 + y^2]
Z2[x_, y_] := 2 - x^2 - y^2

Show[Plot3D[{Z1[x, y], Z2[x, y]}, {x, -1, 1}, {y, -1, 1}],
ParametricPlot3D[{
{x, -1, t Z1[x, -1] + (1 - t) Z2[x, -1]},
{x, 1, t Z1[x, 1] + (1 - t) Z2[x, 1]},
{-1, x, t Z1[-1, x] + (1 - t) Z2[-1, x]},
{1, x, t Z1[-1, x] + (1 - t) Z2[1, x]}}
, {t, 0, 1}, {x, -1, 1}],
BoxRatios -> Automatic]


-