473,394 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Circle-circle intersection and more

7
Hi everyone,

I have a java method public static String circleRelation(double x1, double y1, double r1, double x2, double y2, double r2) that - given two circles in the plane - will decide whether those circles (1) encircle each other, (2) intersect, (3) touch or (4) are totally seperate. The method returns a String which describes the relationship between those circles, e.g.:
The first circle encircles the second circle
The circles intersect
The circles touch each other
The circles are seperate

Do you have any sample codes to write especially about circles intersect?
May 11 '07 #1
3 23181
prometheuzz
197 Expert 100+
Hi everyone,

I have a java method public static String circleRelation(double x1, double y1, double r1, double x2, double y2, double r2) that - given two circles in the plane - will decide whether those circles (1) encircle each other, (2) intersect, (3) touch or (4) are totally seperate. The method returns a String which describes the relationship between those circles, e.g.:
The first circle encircles the second circle
The circles intersect
The circles touch each other
The circles are seperate

Do you have any sample codes to write especially about circles intersect?
I once wrote such a thing and used this page as a reference:
http://mathworld.wolfram.com/Circle-...ersection.html

Checkout reply #10 from this thread:
<Link removed by Admin: Linking to other forums is against site rules>
where I gave an example of how to create such a method.

Good luck.
May 11 '07 #2
prometheuzz
197 Expert 100+
...
<Link removed by Admin: Linking to other forums is against site rules>
...
OK, then I'll cross post my answer.



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 - a^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.  
  8. x4_ii = x3 - (h * (y2 - y1)) / d
  9.       = -10.29 - (6.86 * (-5 - 1)) / 15.23
  10.       = -7.59
  11. y4_ii = y3 + (h * (x2 - x1)) / d
  12.       = 1.55 + (6.86 * (5 - -9)) / 15.23
  13.       = 7.86
So, as you can see, the intersection points are (-12.99, -4.75) and (-7.59, 7.86).
May 12 '07 #3
there is java code to do this:

https://github.com/Lanchon/circle-circle-intersection
Nov 11 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Antoine Logean | last post by:
Hi, What is the easiest way to get the intersection of two strings in python (a kind a "and" operator) ? ex: string_1 =...
17
by: Gordon Williams | last post by:
Hi, I have to lists that I need to find the common numbers (2nd rounded to nearest integral) and I am wondering if there is a more efficient way of doing it. >>> a= >>> b= >>> ...
3
by: Alain Frisch | last post by:
Hello, The following rule in the XML Schema spec, section "Schema Component Constraint: Attribute Wildcard Intersection" seems strange to me: ======================================= 3 If...
2
by: James Stroud | last post by:
Hello All, I find myself in this situation from time to time: I want to compare two lists of arbitrary objects and (1) find those unique to the first list, (2) find those unique to the second...
4
by: Sebastian Cohen S | last post by:
Hello, I am new to SQL and currently using Access 2003 and need a little help on the following. I have two queries each contains one column formed with a string that is very similar (only...
6
by: kimos | last post by:
hi all, how to calculate the intersection of 2 rectangle a rectangle is the following: Rectangle makeRectangle (Point lowerLeft, Point upperRight) { Rectangle r;
2
by: sicapitan | last post by:
Hi There :) Is it possible to get the 4 corners where 2 dives intersect? I'm making a table-ish system and som drag and drop elements need to snap to the area intersecting between 2 divs. I...
2
by: mkppk | last post by:
I have kind of strange change I'd like to make to the sets.Set() intersection() method.. Normally, intersection would return items in both s1 and s2 like with something like this: ...
11
by: Prateek | last post by:
I have 3 variable length lists of sets. I need to find the common elements in each list (across sets) really really quickly. Here is some sample code: # Doesn't make sense to union the sets -...
35
by: Bjoern Hoehrmann | last post by:
Hi, For a free software project, I had to write a routine that, given a Unicode scalar value U+0000 - U+10FFFF, returns an integer that holds the UTF-8 encoded form of it, for example, U+00F6...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.