I'm trying to figure out how to get the distance from two circles relative to the corners of their square container boxes. I need some help with the maths here.
How can I work out the number of pixels for the line marked with a question mark?
Appreciate the help as always.
tldr: Calculate the distance between each circles center point, then subtract the radius' of each circle from that.
For the purpose of a demonstration, we will assume the following:
r1 = 100
) circle is at the (x, y) coordinates of (0, 0)
, andr2 = 50
) circle is at (x, y) coordinates of (150, -150)
.Given that the distance between their centers is:
To find the distance between their boundaries, we subtract the radius of each circle from the distance between their centers.
This leaves us with the equation:
sqrt((x2 − x1)^2 + (y2 − y1)^2) − (r2 + r1)
Inserting your values into the above gives:
sqrt((150 − 0)^2 + (-150 − 0)^2) − (100 + 50) = 62.132034356px
Do you have the middle point of each circles? If you do, first calculate the distance from the centre of circles.
distance² = center1² + center2²
Then, you will need to minus the radius of both circles. In your case, it will be 150 (100 + 50)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With