0
$\begingroup$
--------------
| 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

$\endgroup$
  • 1
    $\begingroup$ 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. $\endgroup$ – EuklidAlexandria Sep 7 '18 at 11:13
  • $\begingroup$ @EuklidAlexandria ah! So I could just subtract half the size after finding the distance, and just make sure distance doesn't go below 0! $\endgroup$ – Zephni Sep 7 '18 at 11:21
  • $\begingroup$ 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. $\endgroup$ – EuklidAlexandria Sep 7 '18 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.