11

As the title says, I have 3 Circle.

Each one have different radius. I know the radius of each circles.

Also know the center points of each circle.

Now I need to know how I can calculate the intersecting point of three circles programmatically, is there is any formula or something?

It may look like below image enter image description here

Alex Chengalan
  • 8,211
  • 4
  • 42
  • 56
  • This is not a programming question at all, and just searching stackoverflow or just google for this will give you a lot of good results. – LionC Nov 01 '13 at 09:03
  • @Alex Chengalan do you want co - ordinates of inserting point? – TheFlash Nov 01 '13 at 09:07
  • @Indiandroid yes I need co- ordinates of **intersecting points** – Alex Chengalan Nov 01 '13 at 09:09
  • Three circles do not necessarily intersect in one point – Henry Nov 01 '13 at 09:19
  • @Alex Chengalan if possible then try to add image.so that it will be more helpful to understand. – TheFlash Nov 01 '13 at 09:32
  • @Indiandroid Question edited – Alex Chengalan Nov 01 '13 at 09:37
  • @Henry There is a possible situation like shown in the picture! – Alex Chengalan Nov 01 '13 at 09:47
  • 2
    i have find the correct solution for this...check this http://sg.answers.yahoo.com/question/index?qid=20110127015240AA9RjyZ but now matter is how to do this in JAVA.@Alex Chengalan – TheFlash Nov 01 '13 at 09:50
  • You want one point which is common for all three circles right? You know that may not always happen. For example, all three circle intersect and there is no common point for all three.. (if your answer is yes.. then please take a look at my answer..) – Amulya Khare Nov 01 '13 at 09:57
  • @AmulyaKhare In my case, there should be a point like the picture. – Alex Chengalan Nov 01 '13 at 10:04
  • @Indiandroid Yes I've seen the answer there. But difficult to do it in JAVA :( , thanks for the time bro! – Alex Chengalan Nov 01 '13 at 10:19
  • See my updated answer.. someone needs to test it out with different cases. Works for most that I have tried. – Amulya Khare Nov 01 '13 at 10:56
  • 4
    This question appears to be off-topic because it is not about programming – Richard Tingle Nov 01 '13 at 11:19
  • 1
    @RichardTingle: Believe it or not, programming is not just about hacking out code. It involves problem solving and on occasion math that you have to implement. This question is clearly a programming question to implement a difficult math-oriented problem, and for those of us who have math skills and work in this area, it is very appreciated. – stackoverflowuser2010 Sep 20 '16 at 06:55
  • @stackoverflowuser2010. This is a question from 3 years ago! But I will say; I have written a 3d physics engine from scratch so I know maths, but any problems I had in it would likely end up in a maths or physics stack exchange – Richard Tingle Sep 20 '16 at 07:43

2 Answers2

10

You could get help from this C code. Porting it to Java should not be challenging. Explanation is here. Search for/scroll to: intersection of two circles

Using this method, find the intersection of any two circles, let's say (x,y). Now the third circle will intersect at point x,y only if distance between its center and point x,y is equal to r.

  1. If distance(center,point) == r, then x,y is the intersection point.

  2. If distance(center,point) != r, then no such point exists.

Code (ported from here; all credit goes to original author):

private boolean calculateThreeCircleIntersection(double x0, double y0, double r0,
                                                 double x1, double y1, double r1,
                                                 double x2, double y2, double r2)
{
    double a, dx, dy, d, h, rx, ry;
    double point2_x, point2_y;

    /* dx and dy are the vertical and horizontal distances between
    * the circle centers.
    */
    dx = x1 - x0;
    dy = y1 - y0;

    /* Determine the straight-line distance between the centers. */
    d = Math.sqrt((dy*dy) + (dx*dx));

    /* Check for solvability. */
    if (d > (r0 + r1))
    {
        /* no solution. circles do not intersect. */
        return false;
    }
    if (d < Math.abs(r0 - r1))
    {
        /* no solution. one circle is contained in the other */
        return false;
    }

    /* 'point 2' is the point where the line through the circle
    * intersection points crosses the line between the circle
    * centers.
    */

    /* Determine the distance from point 0 to point 2. */
    a = ((r0*r0) - (r1*r1) + (d*d)) / (2.0 * d) ;

    /* Determine the coordinates of point 2. */
    point2_x = x0 + (dx * a/d);
    point2_y = y0 + (dy * a/d);

    /* Determine the distance from point 2 to either of the
    * intersection points.
    */
    h = Math.sqrt((r0*r0) - (a*a));

    /* Now determine the offsets of the intersection points from
    * point 2.
    */
    rx = -dy * (h/d);
    ry = dx * (h/d);

    /* Determine the absolute intersection points. */
    double intersectionPoint1_x = point2_x + rx;
    double intersectionPoint2_x = point2_x - rx;
    double intersectionPoint1_y = point2_y + ry;
    double intersectionPoint2_y = point2_y - ry;

    Log.d("INTERSECTION Circle1 AND Circle2:", "(" + intersectionPoint1_x + "," + intersectionPoint1_y + ")" + " AND (" + intersectionPoint2_x + "," + intersectionPoint2_y + ")");

    /* Lets determine if circle 3 intersects at either of the above intersection points. */
    dx = intersectionPoint1_x - x2;
    dy = intersectionPoint1_y - y2;
    double d1 = Math.sqrt((dy*dy) + (dx*dx));

    dx = intersectionPoint2_x - x2;
    dy = intersectionPoint2_y - y2;
    double d2 = Math.sqrt((dy*dy) + (dx*dx));

    if(Math.abs(d1 - r2) < EPSILON) {
        Log.d("INTERSECTION Circle1 AND Circle2 AND Circle3:", "(" + intersectionPoint1_x + "," + intersectionPoint1_y + ")");
    }
    else if(Math.abs(d2 - r2) < EPSILON) {
        Log.d("INTERSECTION Circle1 AND Circle2 AND Circle3:", "(" + intersectionPoint2_x + "," + intersectionPoint2_y + ")"); //here was an error
    }
    else {
        Log.d("INTERSECTION Circle1 AND Circle2 AND Circle3:", "NONE");
    }
    return true;
}

Call this method as follows:

calculateThreeCircleIntersection(-2.0, 0.0, 2.0, // circle 1 (center_x, center_y, radius)
                                  1.0, 0.0, 1.0, // circle 2 (center_x, center_y, radius)
                                  0.0, 4.0, 4.0);// circle 3 (center_x, center_y, radius)

Also, define EPSILON to a small value that is acceptable for your application requirements

private static final double EPSILON = 0.000001;

Note: Maybe some one should test and verify if the results are correct. I can't find any easy way to do so..works for the basic cases that I have tried.

Community
  • 1
  • 1
Amulya Khare
  • 7,718
  • 2
  • 23
  • 38
  • thanks for your effort bro! I will check it and comment here. – Alex Chengalan Nov 01 '13 at 11:08
  • works perfectly! Thanks ! – Vinay W Sep 04 '15 at 13:54
  • I translated the above to Python but with your provided numbers I get : `$ INFO:log:INTERSECTION Circle1 AND Circle2: (0.0,0.0) AND (0.0,0.0) $ INFO:log:INTERSECTION Circle1 AND Circle2 AND Circle3: (0.0,0.0)`. What output should I be expecting given the above input to your function? – AlienWebguy Dec 29 '17 at 17:38
4

You can use the following condition:

(x - x0) ^ 2 + (y - y0) ^ 2 <= R ^ 2

where x and y - coordinates of your point , x0 and y0 - coordinates of the center of the circle , R - radius of the circle , ^ 2 - squaring . If the condition is satisfied, the point is inside (or on the circumference in the case of equality of the left and right parts). If not satisfied, the point is outside the circle .

/ / Point, which hit the circle is necessary to determine
PointF p = ...;

/ / Center of the circle
PointF center = new PointF (10, 10);

/ / The radius of the circle
float r = 5F;

/ / "Normalize" the situation relative to the center point of the circle
float dx = p.x - center.x;
float dy = p.y - center.y;

/ / Compare the distance from the point to the center of a circle to its radius
boolean result =  ((r * r) <= (dx * dx + dy * dy))) ? true : false;