How to calculate the intersection of two circles (Java)

Posted: July 3, 2011 in Java

Let’s say you’re trying to find the intersection points of the circles C1 and C2 where C1 has it’s center point at (-9, 1) and has a radius of 7, and C2’s center lies at (5, -5) and has a radius of 18.
Note that I posted the image to make clear what the variables names in the formula’s are.

First calculate the distance, ‘d’, between the center-points of the two circles:

Expand|Select|Wrap|Line Numbers
  1. d = √(|-9 – 5| + |1 – -5|)
  2.   = 15.23

Now we calculate ‘d1’:

Expand|Select|Wrap|Line Numbers
  1. d1 = (r1^2 – r2^2 + d^2) / 2*d
  2.    = (7^2 – 18^2 + 15.23^2) / 2*15.23
  3.    = (49 – 324 + 231.95) / 30.46
  4.    = -43.05 / 30.46
  5.    = -1.41

Now we solve ‘h’, which is 1/2 * ‘a’

Expand|Select|Wrap|Line Numbers
  1. h = √(r1^2 – d1^2)
  2.   = √(7^2 – -1.41^2)
  3.   = √(49 – 1.99)
  4.   = 6.86

To find point P3(x3,y3) which is the intersection of line ‘d’ and ‘a’ we use the following formula:

Expand|Select|Wrap|Line Numbers
  1. x3 = x1 + (d1 * (x2 – x1)) / d
  2.    = -9 + (-1.41 * (5 – -9)) / 15.23
  3.    = -10.29
  4. y3 = y1 + (d1 * (y2 – y1)) / d
  5.    = 1 + (-1.41 * (-5 – 1)) / 15.23
  6.    = 1.55

Last but not least, calculate the points P4_i and P4_ii which are the intersection points of the two circles:

Expand|Select|Wrap|Line Numbers
  1. x4_i = x3 + (h * (y2 – y1)) / d
  2.      = -10.29 + (6.86 * (-5 – 1)) / 15.23
  3.      = -12.99
  4. y4_i = y3 – (h * (x2 – x1)) / d
  5.      = 1.55 – (6.86 * (5 – -9)) / 15.23
  6.      = -4.75
  7. x4_ii = x3 – (h * (y2 – y1)) / d
  8.       = -10.29 – (6.86 * (-5 – 1)) / 15.23
  9.       = -7.59
  10. y4_ii = y3 + (h * (x2 – x1)) / d
  11.       = 1.55 + (6.86 * (5 – -9)) / 15.23
  12.       = 7.86

So, as you can see, the intersection points are (-12.99, -4.75) and (-7.59, 7.86)

Reference

http://bytes.com/topic/java/answers/645269-circle-circle-intersection-more

Advertisements
Comments
  1. Thanks for the marvelous posting! I truly enjoyed reading it, you happen to be a great author.

    I will make certain to bookmark your blog and may come back in the future.

    I want to encourage you to continue your great posts, have a nice holiday
    weekend!

  2. Great article! We are linking to this particularly great article on our website.

    Keep up the great writing.

  3. WOW just what I was looking for. Came here by searching for skyline

  4. I enjoy what you guys are usually up too. This
    type of clever work and reporting! Keep up the wonderful works guys
    I’ve added you guys to my own blogroll.

  5. cellulite says:

    Having read this I believed it was rather enlightening.

    I appreciate you taking the time and energy to put
    this content together. I once again find myself personally spending
    a significant amount of time both reading and commenting.

    But so what, it was still worthwhile!

  6. troymoyeeex says:

    Hi there this is somewhat of off topic but I was wondering if
    blogs use WYSIWYG editors or if you have to manually code with
    HTML. I’m starting a blog soon but have no coding knowledge so I wanted to get guidance from someone with experience. Any help would be greatly appreciated!

  7. webcamchat says:

    Quality articles or reviews is the key to attract the viewers to pay a quick visit the web
    page, that’s what this website is providing.

  8. Generally I don’t read article on blogs, but I wish to say that this write-up very compelled me to check out and do it! Your writing taste has been surprised me. Thanks, very great article.

  9. It’s remarkable in support of me to have a web page, which is useful in favor of my knowledge. thanks admin

  10. Fotki.Com says:

    Hi, yes this article is actually fastidious and I have learned lot of things from it concerning blogging.
    thanks.

  11. dani says:

    Having read this I thought it was really informative. I appreciate you spending some time and energy to put this short article together. I once again find myself personally spending a significant amount of time both reading and posting comments. But so what, it was still worth it!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s