# Plot the 3D complement

I have plotted a 3D region using

Show[RegionPlot3D[set1, opt1], RegionPlot3D[set2, opt2], RegionPlot3D[set3, opt3]]


So this command plots the union in $\mathbb R^3$ of the three sets $\text{set}_1\cup\text{set}_2\cup\text{set}_3$. My question is: is there a fast way to plot the complement of the union, i.e. to plot $(\text{set}_1\cup\text{set}_2\cup\text{set}_3)^c$?

If I'm not mistaken, a complement is defined as the set of elements in one set that are not contained in a given other set. In your case, you have specified the 'other' set (the union of S1, S2 and S3), but not the 'one' set. As you phrased it, I guess that set must be $\mathbb R^3$. So, the complement is the difference between an infinite space and a finite space. That may be hard to visualize.

Let's try it with a few example sets.

You mention you have three separate RegionPlot-s:

rp1 = RegionPlot3D[x^2 + y^2 + z^2 < 1, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}];
rp2 = RegionPlot3D[(x - 1)^2 + y^2 + z^2 < 1, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}];
rp3 = RegionPlot3D[(x + 1)^2 + y^2 + z^2 < 1, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}];
Show[rp1, rp2, rp3, PlotRange -> All, BoxRatios -> Automatic,
Boxed -> False, Axes -> None]


These regions could have been combined in the same plot by using Or (||):

RegionPlot3D[x^2 + y^2 + z^2 < 1 ||
(x - 1)^2 + y^2 + z^2 < 1 ||
(x + 1)^2 + y^2 + z^2 < 1,
{x, -2, 2}, {y, -2, 2}, {z, -2, 2},
BoxRatios -> Automatic, Boxed -> False, Axes -> None]


The complement could then have been achieved using Not:

RegionPlot3D[
Not[x^2 + y^2 + z^2 < 1 ||
(x - 1)^2 + y^2 + z^2 < 1 ||
(x + 1)^2 + y^2 + z^2 < 1
],
{x, -2, 2}, {y, -2, 2}, {z, -2, 2},
BoxRatios -> Automatic, Boxed -> False, Axes -> None]


Not very interesting. The cut-out' is hiding somewhere in there. Let's try to visualize that using transparency:

RegionPlot3D[
Not[x^2 + y^2 + z^2 < 1 ||
(x - 1)^2 + y^2 + z^2 < 1 ||
(x + 1)^2 + y^2 + z^2 < 1
],
{x, -2, 2}, {y, -2, 2}, {z, -2, 2},
BoxRatios -> Automatic, Boxed -> False, Axes -> None,
PlotStyle -> Opacity[0.3]]


and removing the mesh:

RegionPlot3D[
Not[x^2 + y^2 + z^2 < 1 ||
(x - 1)^2 + y^2 + z^2 < 1 ||
(x + 1)^2 + y^2 + z^2 < 1
],
{x, -2, 2}, {y, -2, 2}, {z, -2, 2},
BoxRatios -> Automatic, Boxed -> False, Axes -> None,
PlotStyle -> Opacity[0.3], Mesh -> None]


Or just plotting half of the above space (leave away positive z):

RegionPlot3D[
Not[x^2 + y^2 + z^2 < 1 ||
(x - 1)^2 + y^2 + z^2 < 1 ||
(x + 1)^2 + y^2 + z^2 < 1
],
{x, -2, 2}, {y, -2, 2}, {z, -2, 0},
BoxRatios -> Automatic, Boxed -> False, Axes -> None]


• Pretty pictures! \o/ +1 Commented Nov 11, 2015 at 11:30

You can use BooleanRegion, if your version is 10.0 or later.

The following gives you the complement region $(\text{region}1\cup\text{region2}\cup\text{region3})^c$ :

BooleanRegion[Not, {RegionUnion[region1,region2,region3]}]


As an example,

region1 = Ball[{-1, 0, 0}, 1];
region2 = Ball[{0, 0, 0}, 1];
region3 = Ball[{+1, 0, 0}, 1];
complement = BooleanRegion[Not, {RegionUnion[region1, region2, region3]}];

BoundaryDiscretizeRegion[Region[complement], MeshCellStyle -> {{2, All} -> Opacity[0.5]}]
`