# How to embed a filled Region in a Graphics?

Let for example:

regn = RegionDifference[Rectangle[{-2, -2}, {2, 2}], Disk[{0, 0}, 1]];


The only documented way I found to draw a gereric region regn filled is a bit "complex":

RegionPlot[RegionMember[regn, {x, y}], {x, -5, 5}, {y, -5, 5}] There is a direct way to make a Graphics object with some filled generic region regn and other graphics primitives like Line, Disk, Rectangle without resorting to use RegionPlot and then Show to combine different Graphic-s?

I'm interested to a generic way for a generic region, not only for the region in the example.

• What do you mean with "not exactly readable"? Nov 21 '14 at 14:30
• Graphics[{Lighter[Blue], Rectangle[{-2, -2}, {2, 2}], White, Disk[{0, 0}, 1]}, PlotRange -> {{-5, 5}, {-5, 5}}, Frame -> True] Nov 21 '14 at 14:31

Building on your self-answer here is an example of using the primitives generated by RegionPlot inside another Graphics expression:

regn = RegionDifference[Rectangle[{-2, -2}, {2, 2}], Disk[{0, 0}, 1]];

elem = RegionPlot[regn][];

Graphics[{Polygon[{{-2, -2}, {3, 3}, {-2, 3}, {3, -2}}],
elem, {Orange, Disk[{0, 0}, 1.5, {Pi/4, 3 Pi/4}]}}] If a different style is needed for the region its hard-coded Directives can be stripped:

elem2 = DeleteCases[elem, _Directive, -1];

Graphics[{Polygon[{{-2, -2}, {3, 3}, {-2, 3}, {3, -2}}],
{Brown, elem2}, {Orange, Disk[{0, 0}, 1.5, {Pi/4, 3 Pi/4}]}}] • Simple and effective, as you are used to be, thanks! Dec 22 '14 at 17:24

It appear that plotting a Region can be simply done by passing the region to RegionPlot without any range specification. At the time the question was asked this use of RegionPlot wasn't documented.

regn = RegionDifference[Rectangle[{-2, -2}, {2, 2}], Disk[{0, 0}, 1]];
RegionPlot[regn]


My question was originally also about a way to combine a filled region with Others graphics primitives without using Show. I think Show it's an effective way to do this, if we want to keep the region's generality, but have a look at the Mr.Wizard answer.

• Thanks for the self-answer; I wasn't aware of this. Dec 22 '14 at 16:43

You can sort of achieve it with DiscretizeRegion and BoundaryMesh

regn = BoundaryMesh@DiscretizeRegion@
RegionDifference[Rectangle[{-2, -2}, {2, 2}], Disk[{0, 0}, 1]]

Show[regn, Graphics@Line[{{0, 0}, {3, 1}}]] MeshRegions (what DiscretizeRegion generates) have many styling options.

Perhaps the MeshPrimitives function allows us to move toward a more canonical way of adding regions to Graphics(3D) without resorting to RegionPlot + extraction + style deletion. Here is Mr. Wizard's second example converted to this form and another example in 3D, which is what I was tinkering with that led me to this question.

Graphics[{Polygon[{{-2, -2}, {3, 3}, {-2, 3}, {3, -2}}], {Brown,
EdgeForm@Brown,
MeshPrimitives[DiscretizeRegion@regn, 1 | 2]}, {Orange,
Disk[{0, 0}, 1.5, {Pi/4, 3 Pi/4}]}}] Graphics3D[{EdgeForm[], Gray, Opacity@.2, Sphere[], Brown, Opacity@1,
Cuboid[{-1, -1, -2}, {1, 1, -1}], Blue,
MeshPrimitives[
BoundaryDiscretizeRegion@
RegionDifference[Ball[], Cuboid[{-1, -1, -1/3}, {1, 1, 1}]], 2]},
Boxed -> False] 