Calculate Overlapping Area of $2$-Dimensional Shapes












0












$begingroup$


I am running a Computer Simulation where 2 Shapes are moving towards each other and will eventually overlap.
I want to calculate the overlapping Area of the shapes - in this example a Circle and a Square in a $2$-Dimensional Room.



Let's describe the Circle as $(x_r, y_r, r)$ and the square as $(x_s, y_s, w, h)$.



Unfortunately I don't find the hint that shows me how to start approaching this problem.
How do I start solving this problem?










share|cite|improve this question











$endgroup$












  • $begingroup$
    Well there is not much context though
    $endgroup$
    – ElHombre
    Jan 11 at 8:49










  • $begingroup$
    @ElHombre What's your motivation for asking this question?
    $endgroup$
    – Toby Mak
    Jan 11 at 9:45










  • $begingroup$
    I want to use a specific area size as a trigger. As the idea is that The objects and movements can be set randomly The mentioned Parameters are the only that I can determine for that moment. I think I could also get the Points of Intersection, that might make things easier, won't it?
    $endgroup$
    – ElHombre
    Jan 15 at 2:43
















0












$begingroup$


I am running a Computer Simulation where 2 Shapes are moving towards each other and will eventually overlap.
I want to calculate the overlapping Area of the shapes - in this example a Circle and a Square in a $2$-Dimensional Room.



Let's describe the Circle as $(x_r, y_r, r)$ and the square as $(x_s, y_s, w, h)$.



Unfortunately I don't find the hint that shows me how to start approaching this problem.
How do I start solving this problem?










share|cite|improve this question











$endgroup$












  • $begingroup$
    Well there is not much context though
    $endgroup$
    – ElHombre
    Jan 11 at 8:49










  • $begingroup$
    @ElHombre What's your motivation for asking this question?
    $endgroup$
    – Toby Mak
    Jan 11 at 9:45










  • $begingroup$
    I want to use a specific area size as a trigger. As the idea is that The objects and movements can be set randomly The mentioned Parameters are the only that I can determine for that moment. I think I could also get the Points of Intersection, that might make things easier, won't it?
    $endgroup$
    – ElHombre
    Jan 15 at 2:43














0












0








0





$begingroup$


I am running a Computer Simulation where 2 Shapes are moving towards each other and will eventually overlap.
I want to calculate the overlapping Area of the shapes - in this example a Circle and a Square in a $2$-Dimensional Room.



Let's describe the Circle as $(x_r, y_r, r)$ and the square as $(x_s, y_s, w, h)$.



Unfortunately I don't find the hint that shows me how to start approaching this problem.
How do I start solving this problem?










share|cite|improve this question











$endgroup$




I am running a Computer Simulation where 2 Shapes are moving towards each other and will eventually overlap.
I want to calculate the overlapping Area of the shapes - in this example a Circle and a Square in a $2$-Dimensional Room.



Let's describe the Circle as $(x_r, y_r, r)$ and the square as $(x_s, y_s, w, h)$.



Unfortunately I don't find the hint that shows me how to start approaching this problem.
How do I start solving this problem?







geometry circle area






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited Jan 11 at 8:48







ElHombre

















asked Jan 11 at 8:17









ElHombreElHombre

62




62












  • $begingroup$
    Well there is not much context though
    $endgroup$
    – ElHombre
    Jan 11 at 8:49










  • $begingroup$
    @ElHombre What's your motivation for asking this question?
    $endgroup$
    – Toby Mak
    Jan 11 at 9:45










  • $begingroup$
    I want to use a specific area size as a trigger. As the idea is that The objects and movements can be set randomly The mentioned Parameters are the only that I can determine for that moment. I think I could also get the Points of Intersection, that might make things easier, won't it?
    $endgroup$
    – ElHombre
    Jan 15 at 2:43


















  • $begingroup$
    Well there is not much context though
    $endgroup$
    – ElHombre
    Jan 11 at 8:49










  • $begingroup$
    @ElHombre What's your motivation for asking this question?
    $endgroup$
    – Toby Mak
    Jan 11 at 9:45










  • $begingroup$
    I want to use a specific area size as a trigger. As the idea is that The objects and movements can be set randomly The mentioned Parameters are the only that I can determine for that moment. I think I could also get the Points of Intersection, that might make things easier, won't it?
    $endgroup$
    – ElHombre
    Jan 15 at 2:43
















$begingroup$
Well there is not much context though
$endgroup$
– ElHombre
Jan 11 at 8:49




$begingroup$
Well there is not much context though
$endgroup$
– ElHombre
Jan 11 at 8:49












$begingroup$
@ElHombre What's your motivation for asking this question?
$endgroup$
– Toby Mak
Jan 11 at 9:45




$begingroup$
@ElHombre What's your motivation for asking this question?
$endgroup$
– Toby Mak
Jan 11 at 9:45












$begingroup$
I want to use a specific area size as a trigger. As the idea is that The objects and movements can be set randomly The mentioned Parameters are the only that I can determine for that moment. I think I could also get the Points of Intersection, that might make things easier, won't it?
$endgroup$
– ElHombre
Jan 15 at 2:43




$begingroup$
I want to use a specific area size as a trigger. As the idea is that The objects and movements can be set randomly The mentioned Parameters are the only that I can determine for that moment. I think I could also get the Points of Intersection, that might make things easier, won't it?
$endgroup$
– ElHombre
Jan 15 at 2:43










1 Answer
1






active

oldest

votes


















0












$begingroup$

Hint:



This is a pretty complex problem as there are many possible cases, but you can address it in a manageable way by the sweepline approach.



Draw horizontals by the square corners and by the N and S pole of the circle. The two shapes delimit line segments on these horizontals, and finding the intersection of two segments is trivial. When you go down from one line to the next, if the endpoints switch position, you have an intersection between the circle and the square outlines.



Scanning all horizontals in turn, you can follow the outline of the intersection shape, and as you go you describe curvilinear trapezoids (the oblique sides are circular arcs). Now it "suffices" to accumulate the areas of these trapezoids, using the standard formula, corrected with the areas of circular segments.



enter image description here





Warning:



The criterion "if the endpoints switch position" is not sufficient. You can very well have a large arc which is intersected twice by a vertical side, so that the endpoints switch position twice. So it is safer to write a test that explicitly looks for intersections between an arc and a vertical line in the current vertical span.






share|cite|improve this answer











$endgroup$













  • $begingroup$
    that sounds like a pretty good solution, it nearly covers all possibilities right?
    $endgroup$
    – ElHombre
    Jan 15 at 5:52










  • $begingroup$
    @ElHombre: if you take care, it covers all possibilities. I have added a warning.
    $endgroup$
    – Yves Daoust
    Jan 15 at 8:41













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: "69"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3069603%2fcalculate-overlapping-area-of-2-dimensional-shapes%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0












$begingroup$

Hint:



This is a pretty complex problem as there are many possible cases, but you can address it in a manageable way by the sweepline approach.



Draw horizontals by the square corners and by the N and S pole of the circle. The two shapes delimit line segments on these horizontals, and finding the intersection of two segments is trivial. When you go down from one line to the next, if the endpoints switch position, you have an intersection between the circle and the square outlines.



Scanning all horizontals in turn, you can follow the outline of the intersection shape, and as you go you describe curvilinear trapezoids (the oblique sides are circular arcs). Now it "suffices" to accumulate the areas of these trapezoids, using the standard formula, corrected with the areas of circular segments.



enter image description here





Warning:



The criterion "if the endpoints switch position" is not sufficient. You can very well have a large arc which is intersected twice by a vertical side, so that the endpoints switch position twice. So it is safer to write a test that explicitly looks for intersections between an arc and a vertical line in the current vertical span.






share|cite|improve this answer











$endgroup$













  • $begingroup$
    that sounds like a pretty good solution, it nearly covers all possibilities right?
    $endgroup$
    – ElHombre
    Jan 15 at 5:52










  • $begingroup$
    @ElHombre: if you take care, it covers all possibilities. I have added a warning.
    $endgroup$
    – Yves Daoust
    Jan 15 at 8:41


















0












$begingroup$

Hint:



This is a pretty complex problem as there are many possible cases, but you can address it in a manageable way by the sweepline approach.



Draw horizontals by the square corners and by the N and S pole of the circle. The two shapes delimit line segments on these horizontals, and finding the intersection of two segments is trivial. When you go down from one line to the next, if the endpoints switch position, you have an intersection between the circle and the square outlines.



Scanning all horizontals in turn, you can follow the outline of the intersection shape, and as you go you describe curvilinear trapezoids (the oblique sides are circular arcs). Now it "suffices" to accumulate the areas of these trapezoids, using the standard formula, corrected with the areas of circular segments.



enter image description here





Warning:



The criterion "if the endpoints switch position" is not sufficient. You can very well have a large arc which is intersected twice by a vertical side, so that the endpoints switch position twice. So it is safer to write a test that explicitly looks for intersections between an arc and a vertical line in the current vertical span.






share|cite|improve this answer











$endgroup$













  • $begingroup$
    that sounds like a pretty good solution, it nearly covers all possibilities right?
    $endgroup$
    – ElHombre
    Jan 15 at 5:52










  • $begingroup$
    @ElHombre: if you take care, it covers all possibilities. I have added a warning.
    $endgroup$
    – Yves Daoust
    Jan 15 at 8:41
















0












0








0





$begingroup$

Hint:



This is a pretty complex problem as there are many possible cases, but you can address it in a manageable way by the sweepline approach.



Draw horizontals by the square corners and by the N and S pole of the circle. The two shapes delimit line segments on these horizontals, and finding the intersection of two segments is trivial. When you go down from one line to the next, if the endpoints switch position, you have an intersection between the circle and the square outlines.



Scanning all horizontals in turn, you can follow the outline of the intersection shape, and as you go you describe curvilinear trapezoids (the oblique sides are circular arcs). Now it "suffices" to accumulate the areas of these trapezoids, using the standard formula, corrected with the areas of circular segments.



enter image description here





Warning:



The criterion "if the endpoints switch position" is not sufficient. You can very well have a large arc which is intersected twice by a vertical side, so that the endpoints switch position twice. So it is safer to write a test that explicitly looks for intersections between an arc and a vertical line in the current vertical span.






share|cite|improve this answer











$endgroup$



Hint:



This is a pretty complex problem as there are many possible cases, but you can address it in a manageable way by the sweepline approach.



Draw horizontals by the square corners and by the N and S pole of the circle. The two shapes delimit line segments on these horizontals, and finding the intersection of two segments is trivial. When you go down from one line to the next, if the endpoints switch position, you have an intersection between the circle and the square outlines.



Scanning all horizontals in turn, you can follow the outline of the intersection shape, and as you go you describe curvilinear trapezoids (the oblique sides are circular arcs). Now it "suffices" to accumulate the areas of these trapezoids, using the standard formula, corrected with the areas of circular segments.



enter image description here





Warning:



The criterion "if the endpoints switch position" is not sufficient. You can very well have a large arc which is intersected twice by a vertical side, so that the endpoints switch position twice. So it is safer to write a test that explicitly looks for intersections between an arc and a vertical line in the current vertical span.







share|cite|improve this answer














share|cite|improve this answer



share|cite|improve this answer








edited Jan 15 at 8:45

























answered Jan 11 at 9:08









Yves DaoustYves Daoust

127k673226




127k673226












  • $begingroup$
    that sounds like a pretty good solution, it nearly covers all possibilities right?
    $endgroup$
    – ElHombre
    Jan 15 at 5:52










  • $begingroup$
    @ElHombre: if you take care, it covers all possibilities. I have added a warning.
    $endgroup$
    – Yves Daoust
    Jan 15 at 8:41




















  • $begingroup$
    that sounds like a pretty good solution, it nearly covers all possibilities right?
    $endgroup$
    – ElHombre
    Jan 15 at 5:52










  • $begingroup$
    @ElHombre: if you take care, it covers all possibilities. I have added a warning.
    $endgroup$
    – Yves Daoust
    Jan 15 at 8:41


















$begingroup$
that sounds like a pretty good solution, it nearly covers all possibilities right?
$endgroup$
– ElHombre
Jan 15 at 5:52




$begingroup$
that sounds like a pretty good solution, it nearly covers all possibilities right?
$endgroup$
– ElHombre
Jan 15 at 5:52












$begingroup$
@ElHombre: if you take care, it covers all possibilities. I have added a warning.
$endgroup$
– Yves Daoust
Jan 15 at 8:41






$begingroup$
@ElHombre: if you take care, it covers all possibilities. I have added a warning.
$endgroup$
– Yves Daoust
Jan 15 at 8:41




















draft saved

draft discarded




















































Thanks for contributing an answer to Mathematics 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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3069603%2fcalculate-overlapping-area-of-2-dimensional-shapes%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith