How would I define a region with multiple holes?
$begingroup$
I would like to define a region consisting of a polygon with eight holes in it. This is essentially a stamped piece of metal with eight holes.
a01 = Disk[{-0.5, 1},0.1];
a02 = Disk[{-1.5, 1},0.1];
a03 = Disk[{-2.5, 1},0.1];
a04 = Disk[{-3.5, 1},0.1];
a05 = Disk[{-4.5, 1},0.1];
a06 = Disk[{-5.5, 1},0.1];
a07 = Disk[{-6.5, 1},0.1];
a08 = Disk[{-7.5, 1},0.1];
aRegion = RegionUnion[ a01,
a02,
a03,
a04,
a05,
a06,
a07,
a08 ];
bRegion = Polygon[ {{-12.5,6}, {12.5, 6}, {6.5, 0}, {-6.5, 0}} ];
[CapitalOmega] = Region @ RegionDifference[aRegion, bRegion]
The aRegion is a series of eight holes.

The bRegion is a simple polygon.

I am trying to create a polygon with eight holes. The result of the RegionDifference is shown below.

Note that if I swap the parameters in the call to RegionDifference, I get the bRegion polygon without holes.
What would be the correct way to define a region that is essentially the bRegion polygon minus the aRegion holes?
regions mesh
$endgroup$
add a comment |
$begingroup$
I would like to define a region consisting of a polygon with eight holes in it. This is essentially a stamped piece of metal with eight holes.
a01 = Disk[{-0.5, 1},0.1];
a02 = Disk[{-1.5, 1},0.1];
a03 = Disk[{-2.5, 1},0.1];
a04 = Disk[{-3.5, 1},0.1];
a05 = Disk[{-4.5, 1},0.1];
a06 = Disk[{-5.5, 1},0.1];
a07 = Disk[{-6.5, 1},0.1];
a08 = Disk[{-7.5, 1},0.1];
aRegion = RegionUnion[ a01,
a02,
a03,
a04,
a05,
a06,
a07,
a08 ];
bRegion = Polygon[ {{-12.5,6}, {12.5, 6}, {6.5, 0}, {-6.5, 0}} ];
[CapitalOmega] = Region @ RegionDifference[aRegion, bRegion]
The aRegion is a series of eight holes.

The bRegion is a simple polygon.

I am trying to create a polygon with eight holes. The result of the RegionDifference is shown below.

Note that if I swap the parameters in the call to RegionDifference, I get the bRegion polygon without holes.
What would be the correct way to define a region that is essentially the bRegion polygon minus the aRegion holes?
regions mesh
$endgroup$
add a comment |
$begingroup$
I would like to define a region consisting of a polygon with eight holes in it. This is essentially a stamped piece of metal with eight holes.
a01 = Disk[{-0.5, 1},0.1];
a02 = Disk[{-1.5, 1},0.1];
a03 = Disk[{-2.5, 1},0.1];
a04 = Disk[{-3.5, 1},0.1];
a05 = Disk[{-4.5, 1},0.1];
a06 = Disk[{-5.5, 1},0.1];
a07 = Disk[{-6.5, 1},0.1];
a08 = Disk[{-7.5, 1},0.1];
aRegion = RegionUnion[ a01,
a02,
a03,
a04,
a05,
a06,
a07,
a08 ];
bRegion = Polygon[ {{-12.5,6}, {12.5, 6}, {6.5, 0}, {-6.5, 0}} ];
[CapitalOmega] = Region @ RegionDifference[aRegion, bRegion]
The aRegion is a series of eight holes.

The bRegion is a simple polygon.

I am trying to create a polygon with eight holes. The result of the RegionDifference is shown below.

Note that if I swap the parameters in the call to RegionDifference, I get the bRegion polygon without holes.
What would be the correct way to define a region that is essentially the bRegion polygon minus the aRegion holes?
regions mesh
$endgroup$
I would like to define a region consisting of a polygon with eight holes in it. This is essentially a stamped piece of metal with eight holes.
a01 = Disk[{-0.5, 1},0.1];
a02 = Disk[{-1.5, 1},0.1];
a03 = Disk[{-2.5, 1},0.1];
a04 = Disk[{-3.5, 1},0.1];
a05 = Disk[{-4.5, 1},0.1];
a06 = Disk[{-5.5, 1},0.1];
a07 = Disk[{-6.5, 1},0.1];
a08 = Disk[{-7.5, 1},0.1];
aRegion = RegionUnion[ a01,
a02,
a03,
a04,
a05,
a06,
a07,
a08 ];
bRegion = Polygon[ {{-12.5,6}, {12.5, 6}, {6.5, 0}, {-6.5, 0}} ];
[CapitalOmega] = Region @ RegionDifference[aRegion, bRegion]
The aRegion is a series of eight holes.

The bRegion is a simple polygon.

I am trying to create a polygon with eight holes. The result of the RegionDifference is shown below.

Note that if I swap the parameters in the call to RegionDifference, I get the bRegion polygon without holes.
What would be the correct way to define a region that is essentially the bRegion polygon minus the aRegion holes?
regions mesh
regions mesh
edited Feb 10 at 13:44
Doug Kimzey
asked Feb 10 at 13:35
Doug KimzeyDoug Kimzey
993615
993615
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
$begingroup$
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.
$endgroup$
add a comment |
$begingroup$
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
]
]

$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "387"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f191237%2fhow-would-i-define-a-region-with-multiple-holes%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
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.
$endgroup$
add a comment |
$begingroup$
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.
$endgroup$
add a comment |
$begingroup$
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.
$endgroup$
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.
edited Feb 10 at 17:03
answered Feb 10 at 14:04
Henrik SchumacherHenrik Schumacher
55.8k576154
55.8k576154
add a comment |
add a comment |
$begingroup$
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
]
]

$endgroup$
add a comment |
$begingroup$
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
]
]

$endgroup$
add a comment |
$begingroup$
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
]
]

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

edited Feb 10 at 15:16
answered Feb 10 at 14:54
gwrgwr
8,53322761
8,53322761
add a comment |
add a comment |
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f191237%2fhow-would-i-define-a-region-with-multiple-holes%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown