How would I define a region with multiple holes?
You mixed up the ordering of bRegion
and aRegion
. Moreover, Region
is only suitable for a quick preview; it usually does not discretize very accurately. Try DiscretizeRegion
with variable MaxCellMeasure
instead.
\[CapitalOmega] = DiscretizeRegion[RegionDifference[bRegion, aRegion],
MaxCellMeasure -> 0.001]
You may also try to specify a suitable MeshRefinementFunction
in order to localize the refinement of the mesh around the holes.
As Henrik has pointed out, the holes are there when the parameterization of RegionDifference
is correct. Sometimes having Infix
notation in mind will help to avoid mistakes.
Another advice is to start using contructor functions with parameters defined only once (e.g. using scoping constructs like With
) right from the start. So mind the advice: Don't repeat yourself (DRY). This helps to easily "play around" with what you have done. Using a larger radius, for example, would have quickly shown that the holes are there even in the coarse output produced by Region
but are simply to small (e.g. setting radius to 0.3 would have sufficed).
Next to discretizing there is RegionPlot
, which offers more control with regard to the outcome:
With[
{
r = 0.1, (* radius of holes *)
xmin = -12.5,
xmax = 12.5,
ymin = 0,
ymax = 6,
holesX = Range[-0.5, -7.5, -1],
holesY = 1,
minus = RegionDifference
}
,
aRegion = RegionUnion @ Map[Disk[{#, holesY}, r] &, holesX];
bRegion = Polygon @ { {xmin, ymax}, {xmax, ymax}, {6.5, ymin}, {-6.5, ymin} };
Ω = bRegion ~ minus ~ aRegion; (* infix makes this more readable *)
RegionPlot[ Evaluate @ RegionMember[ Ω, {x, y} ]
, {x, xmin, xmax}
, {y, ymin, ymax}
, AspectRatio -> (ymax - ymin)/(xmax - xmin)
, PlotPoints -> 200
]
]