11
$\begingroup$

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$?

$\endgroup$
0

2 Answers 2

25
$\begingroup$

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]

Mathematica graphics

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]

Mathematica graphics

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]

Mathematica graphics

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]]

Mathematica graphics

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]

Mathematica graphics

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]

Mathematica graphics

$\endgroup$
1
  • $\begingroup$ Pretty pictures! \o/ +1 $\endgroup$
    – LLlAMnYP
    Commented Nov 11, 2015 at 11:30
6
$\begingroup$

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]}]

BoundaryDiscretizeRegion of the complement region

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.