Get distance between two points including size of “entities”.

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












--------------
| p1 |
| p2 |
--------------


The formula to work out the difference between these two elements could be written as:



distance = ((x1-x2)(x1-x2)+(y1-y2)(y1-y2))



-----------------------
| p1p1 |
| p1p1 |
| |
| p2 |
-----------------------


With the above problem though, how would you get the distance if one of the points also had a size? So if p2 was "covering" p1's bounding box then the distance would be 0, and if p2 was 5 to the left or right of p1's bounding box then distance would be 5.



Would someone please show and try to explain a formula for this problem?



Thanks in advance










share|cite|improve this question



















  • 1




    You can calculate the distance between the middle of the bounding box to the other point. Aside from that you have to take the square root of your formula in order to get the distance.
    – EuklidAlexandria
    Sep 7 at 11:13










  • @EuklidAlexandria ah! So I could just subtract half the size after finding the distance, and just make sure distance doesn't go below 0!
    – Zephni
    Sep 7 at 11:21










  • First of all you have to calculate the centre of the bounding box. Then you can calculate the distance from the centre to the other by point with the square root of your formula.
    – EuklidAlexandria
    Sep 7 at 11:32














up vote
0
down vote

favorite












--------------
| p1 |
| p2 |
--------------


The formula to work out the difference between these two elements could be written as:



distance = ((x1-x2)(x1-x2)+(y1-y2)(y1-y2))



-----------------------
| p1p1 |
| p1p1 |
| |
| p2 |
-----------------------


With the above problem though, how would you get the distance if one of the points also had a size? So if p2 was "covering" p1's bounding box then the distance would be 0, and if p2 was 5 to the left or right of p1's bounding box then distance would be 5.



Would someone please show and try to explain a formula for this problem?



Thanks in advance










share|cite|improve this question



















  • 1




    You can calculate the distance between the middle of the bounding box to the other point. Aside from that you have to take the square root of your formula in order to get the distance.
    – EuklidAlexandria
    Sep 7 at 11:13










  • @EuklidAlexandria ah! So I could just subtract half the size after finding the distance, and just make sure distance doesn't go below 0!
    – Zephni
    Sep 7 at 11:21










  • First of all you have to calculate the centre of the bounding box. Then you can calculate the distance from the centre to the other by point with the square root of your formula.
    – EuklidAlexandria
    Sep 7 at 11:32












up vote
0
down vote

favorite









up vote
0
down vote

favorite











--------------
| p1 |
| p2 |
--------------


The formula to work out the difference between these two elements could be written as:



distance = ((x1-x2)(x1-x2)+(y1-y2)(y1-y2))



-----------------------
| p1p1 |
| p1p1 |
| |
| p2 |
-----------------------


With the above problem though, how would you get the distance if one of the points also had a size? So if p2 was "covering" p1's bounding box then the distance would be 0, and if p2 was 5 to the left or right of p1's bounding box then distance would be 5.



Would someone please show and try to explain a formula for this problem?



Thanks in advance










share|cite|improve this question















--------------
| p1 |
| p2 |
--------------


The formula to work out the difference between these two elements could be written as:



distance = ((x1-x2)(x1-x2)+(y1-y2)(y1-y2))



-----------------------
| p1p1 |
| p1p1 |
| |
| p2 |
-----------------------


With the above problem though, how would you get the distance if one of the points also had a size? So if p2 was "covering" p1's bounding box then the distance would be 0, and if p2 was 5 to the left or right of p1's bounding box then distance would be 5.



Would someone please show and try to explain a formula for this problem?



Thanks in advance







calculus linear-algebra geometry






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited Sep 7 at 10:48

























asked Sep 7 at 10:41









Zephni

1013




1013







  • 1




    You can calculate the distance between the middle of the bounding box to the other point. Aside from that you have to take the square root of your formula in order to get the distance.
    – EuklidAlexandria
    Sep 7 at 11:13










  • @EuklidAlexandria ah! So I could just subtract half the size after finding the distance, and just make sure distance doesn't go below 0!
    – Zephni
    Sep 7 at 11:21










  • First of all you have to calculate the centre of the bounding box. Then you can calculate the distance from the centre to the other by point with the square root of your formula.
    – EuklidAlexandria
    Sep 7 at 11:32












  • 1




    You can calculate the distance between the middle of the bounding box to the other point. Aside from that you have to take the square root of your formula in order to get the distance.
    – EuklidAlexandria
    Sep 7 at 11:13










  • @EuklidAlexandria ah! So I could just subtract half the size after finding the distance, and just make sure distance doesn't go below 0!
    – Zephni
    Sep 7 at 11:21










  • First of all you have to calculate the centre of the bounding box. Then you can calculate the distance from the centre to the other by point with the square root of your formula.
    – EuklidAlexandria
    Sep 7 at 11:32







1




1




You can calculate the distance between the middle of the bounding box to the other point. Aside from that you have to take the square root of your formula in order to get the distance.
– EuklidAlexandria
Sep 7 at 11:13




You can calculate the distance between the middle of the bounding box to the other point. Aside from that you have to take the square root of your formula in order to get the distance.
– EuklidAlexandria
Sep 7 at 11:13












@EuklidAlexandria ah! So I could just subtract half the size after finding the distance, and just make sure distance doesn't go below 0!
– Zephni
Sep 7 at 11:21




@EuklidAlexandria ah! So I could just subtract half the size after finding the distance, and just make sure distance doesn't go below 0!
– Zephni
Sep 7 at 11:21












First of all you have to calculate the centre of the bounding box. Then you can calculate the distance from the centre to the other by point with the square root of your formula.
– EuklidAlexandria
Sep 7 at 11:32




First of all you have to calculate the centre of the bounding box. Then you can calculate the distance from the centre to the other by point with the square root of your formula.
– EuklidAlexandria
Sep 7 at 11:32















active

oldest

votes











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',
convertImagesToLinks: true,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
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%2f2908500%2fget-distance-between-two-points-including-size-of-entities%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2908500%2fget-distance-between-two-points-including-size-of-entities%23new-answer', 'question_page');

);

Post as a guest













































































這個網誌中的熱門文章

How to combine Bézier curves to a surface?

Carbon dioxide

Why am i infinitely getting the same tweet with the Twitter Search API?