# How to plot two regions such that both are visible and also highlight the overlap?

I try to plot the following inequalities f[x,y,z]<=1 and g[x,y,z]<=1 in a single plot such that both the regions are visible and also the intersection is highlighted. I tried the RegionPlot3D but it only shows the region which is common to them.

f[x_, y_, z_] = x + y + z;
g[x_, y_, z_] = x^2 + y^2 + z^2;

RegionPlot3D[f[x, y, z] <= 1, {x, 0, 1}, {y, 0, 1}, {z, 0, 1}]
RegionPlot3D[g[x, y, z] <= 1, {x, 0, 1}, {y, 0, 1}, {z, 0, 1}]

• One of those regions is completely within the other, tho; is something like RegionPlot3D[{x + y + z <= 1, x^2 + y^2 + z^2 <= 1}, {x, 0, 1}, {y, 0, 1}, {z, 0, 1}, PlotStyle -> Opacity[1/3]] what you had in mind? Jul 27 at 17:21

Clear["Global*"]

f[x_, y_, z_] = x + y + z;
g[x_, y_, z_] = x^2 + y^2 + z^2;


Since the region f[x, y, z] <= 1 is completely contained in the region g[x, y, z] <= 1, the intersection is just the smaller region. You cannot distinguish the smaller region from the intersection.

RegionPlot3D[{f[x, y, z] <= 1, g[x, y, z] <= 1,
f[x, y, z] <= 1 && g[x, y, z] <= 1}, {x, 0, 1}, {y, 0, 1}, {z, 0, 1},
PlotStyle -> {Opacity[0.5], Opacity[0.5], Automatic},
PlotLegends -> "Expressions"]


However, if the neither region is completely contained by the other

RegionPlot3D[{f[x, y, z] <= 1, g[x, y, z] <= 1/2,
f[x, y, z] <= 1 && g[x, y, z] <= 1/2}, {x, 0, 1}, {y, 0, 1}, {z, 0, 1},
PlotStyle -> {Opacity[0.5], Opacity[0.5], Automatic},
PlotLegends -> "Expressions"]
`

• Thanks Bob, it worked fine when I copied it first time, but now it is showing "{x+y+z<=1,x^2+y^2+z^2<=1,x+y+z<=1&&x^2+y^2+z^2<=1} must be a Boolean \ function"......don't really understand what's wrong here! Jul 27 at 19:51
• Quit Mathematica and restart it. Copy, paste, and evaluate the code above. Jul 27 at 19:55
• Still showing the same message :-( Jul 27 at 20:09
• What Mathematica version are you using? Jul 27 at 20:10
• 11.3, on Win 10 Jul 27 at 20:16