Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding the distance between two circles

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.

Finding distance between two circles

How can I work out the number of pixels for the line marked with a question mark?

Appreciate the help as always.

like image 287
Alex Avatar asked Apr 01 '11 04:04

Alex


2 Answers

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:

  • The 200px diameter (r1 = 100) circle is at the (x, y) coordinates of (0, 0), and
  • the 100px diameter (r2 = 50) circle is at (x, y) coordinates of (150, -150).

Given that the distance between their centers is: Distance

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
like image 152
deceleratedcaviar Avatar answered Nov 16 '22 01:11

deceleratedcaviar


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)

like image 3
Sufendy Avatar answered Nov 16 '22 00:11

Sufendy