# Calculate the circle that touches three other circles

Given three circles on a cartesian grid (with centres and radii known), how would you calculate the centre of the circle that touches those three?

The three known circles may have any radius length, and may touch or cross each other (but not have overlapping centres), but the calculated circle must lie externally to the three known circles.

See this online graphing tool for an example of how this looks:

https://www.desmos.com/calculator/lf1q90ymrh

Note: Imagine we have the first 3 circles as given (two red ones, plus a black one). The question is: how can we mathematically deduce the formula of the fourth circle - the purple one - that just touches the first three? In this example I added the purple circle by trial-and-error, and it is only approximate.

There is one answer against this question already. It might be correct but I don't understand how to start with 3 concrete circles - like in the link above - and then work out the fourth. I think I need someone to take that linked example, use the numbers there, and explain how to perform the maths to calculate the fourth.

• Are there too many unknowns here? Say you have 3 concentric circles (circles have the same center). Then, the "calculated circle" touching these 3 circles cannot lie externally. It may help if you have a picture. – Akash Patel Feb 5 at 9:05
• Updated: the 3 known circles may not have overlapping centres. – youcantryreachingme Feb 5 at 9:07
• Basically, draw 3 separate dots on a page. Draw 3 circles - one about each dot, of any radial length. There should now be a fourth circle which touches all 3 prior circles without overlapping them - how to find that circle? – youcantryreachingme Feb 5 at 9:08
• About the radius of this circle , it is the problem of Apollonius : en.wikipedia.org/wiki/Problem_of_Apollonius – Jean Marie Feb 6 at 21:29
• Thanks for the link - yes, I'm after the special case where the solved circle does not overlap any of the given circles at all (even if the given circles overlap each other). – youcantryreachingme Feb 7 at 0:59

## 3 Answers

Updated Post

Imagine three circles that are offset by the same value $$r$$ concentric to the three generating circles.

For a special value of $$r$$ the three circles meet, at the center of the tangent circle you want to find.

This can be used to set up three non-linear equation for three unknowns: The circle center $$(x,y)$$ and the radius $$r$$.

\begin{aligned} (x-x_1)^2 + (y-y_1)^2 & = (r_1 + r)^2 \\ (x-x_2)^2 + (y-y_2)^2 & = (r_2 + r)^2 \\ (x-x_3)^2 + (y-y_3)^2 & = (r_3 + r)^2 \\ \end{aligned} \; \tag{1}

The three generating circles have centers $$(x_1,y_1)$$, $$(x_2,y_2)$$, and $$(x_3,y_3)$$, and radii $$r_1$$, $$r_2$$ and $$r_3$$.

To solve the above, subtract the 2nd equation from the 1st, and the 3rd equation from the 1st to generate two linear equations in terms of $$x$$ and $$y$$, but still dependent linearly on $$r$$.

\begin{aligned} 2 x (x_2-x_1) + 2 y (y_2-y_1) = r (2 r_1 -2 r_2 ) + K_a \\ 2 x (x_3-x_1) + 2 y (y_3-y_1) = r (2 r_1 -2 r_3 ) + K_b \end{aligned} \; \tag{2}

with known constants \begin{aligned} K_a & = r_1^2-r_2^2-x_1^2+x_2^2-y_1^2+y_2^2 \\ K_b & = r_1^2-r_3^2-x_1^2+x_3^2-y_1^2+y_3^2 \end{aligned}

The solution to the above system of equations is of the form

\begin{aligned} x & = A_0 + A_1 r \\ y & = B_0 + B_1 r \end{aligned} \; \tag{3}

with known constants \begin{aligned} D & = x_1(y_2-y_3)+x_2(y_3-y_1)+x_3(y_1-y_2) \\ \\ A_0 &= \frac{K_a(y_1-y_3)+K_b(y_2-y_1)}{2 D} \\ B_0 &= -\frac{K_a(x_1-x_3)+K_b(x_2-x_1)}{2 D} \\ A_1 &= -\frac{r_1(y_2-y_3)+r_2(y_3-y_1)+r_3(y_1-y_2)}{D}\\ B_1 &= \frac{r_1(x_2-x_3)+r_2(x_3-x_1)+r_3(x_1-x_2)}{D} \end{aligned}

Finally, take the equation of the first circle, and substitute $$(x,y)$$ from above in order to solve for $$r$$

$$( A_0 + A_1 r-x_1)^2 + (B_0 + B_1 r-y_1)^2 = (r_1+r)^2$$

The above is a single quadratic equation to be solved for $$r$$. Expand into

$$C_0 + 2 C_1 r + C_2 r^2 =0 \; \tag{4}$$

with known constants \begin{aligned} C_0 &= (A_0-x_1)^2 + (B_0-y_1)^2 - r_1^2 \\ C_1 & = A_1 ( A_0-x_1) + B_1 (B_0-y_1) -r_1 \\ C_2 & = A_1^2+B_1^2-1 \end{aligned}

and solutions

$$\boxed{ r = \frac{-C_1 \pm \sqrt{C_1^2-C_0 C_2}}{C_2} } \; \tag{5}$$

Once you have the radius $$r$$ use Equation $$(3)$$ to find the center $$(x,y)$$.

A numerical example with MATLAB is below

%Three circles
x_1=10; y_1=10; r_1 = 2.5;
x_2=4; y_2=3; r_2 = 3;
x_3=3; y_3=7; r_3 = 5;

draw_circle(x_1,y_1,r_1);
draw_circle(x_2,y_2,r_2);
draw_circle(x_3,y_3,r_3);

% Find constant of circle #2- cirlce #1
K_a = -r_1^2+r_2^2+x_1^2-x_2^2+y_1^2-y_2^2
% Find constant of circle #3- cirlce #1
K_b = -r_1^2+r_3^2+x_1^2-x_3^2+y_1^2-y_3^2

% Find constants of [x=A_0+A_1*r, y=B_0+B_1*r]
D = x_1*(y_2-y_3)+x_2*(y_3-y_1)+x_3*(y_1-y_2)
A_0=(K_a*(y_1-y_3)+K_b*(y_2-y_1))/(2*D)
B_0=-(K_a*(x_1-x_3)+K_b*(x_2-x_1))/(2*D)
A_1=-(r_1*(y_2-y_3)+r_2*(y_3-y_1)+r_3*(y_1-y_2))/D
B_1=(r_1*(x_2-x_3)+r_2*(x_3-x_1)+r_3*(x_1-x_2))/D

% Find constants of C_0 + 2*C_1*r + C_2^2 = 0
C_0=A_0^2-2*A_0*x_1+B_0^2-2*B_0*y_1-r_1^2+x_1^2+y_1^2
C_1=A_0*A_1-A_1*x_1+B_0*B_1-B_1*y_1-r_1
C_2=A_1^2+B_1^2-1

% Solve for r
r=(-sqrt(C_1^2-C_0*C_2)-C_1)/C_2
% Solve for [x,y]
x = A_0+A_1*r
y = B_0+B_1*r

%Check results
draw_circle(x,y,r);

function h = draw_circle(x,y,r)
hold on
t = 0:pi/50:2*pi;
x_p = r*cos(t)+x;
y_p = r*sin(t)+y;
h = plot(x_p,y_p);
hold off
end


Output:

NOTE: The other solution with r=(+sqrt(C_1^2-C_0*C_2)-C_1)/C_2 is

• I appreciate the extra detail, compared with the prior answer, and it will take me some time to try and apply these steps to a concrete example. Per the bounty note I was really hoping to see a worked example, with concrete numbers - and I linked to an example question that could be used. If you are able, I would love to see the solution to that example question. In the meantime I will try and derive that answer using your information here. – youcantryreachingme Jul 18 at 0:15
• I tried following the formulas and ended up with the last circle that I have added to the example - it does not appear correct. I will go through and double check my calculations however.. desmos.com/calculator/igv8xrtb9q – youcantryreachingme Jul 18 at 6:55
• The method works. I might have a typo in the solution above though. Here is an example calculation from the circles given in your example. A graph of the result is shown here – ja72 Jul 18 at 12:48
• Fix: in the attached example line #9 should read "Subract #6 from #7, and #6 from #8". – ja72 Jul 18 at 13:45
• @youcantryreachingme - I have updated the post and fixed some typos. I am going to post a numeric example also to show that this works. – ja72 Jul 18 at 14:12

WLOG, one of the given circles is centered at the origin.

Express that the distance between the center of the searched circle and the other centers is the difference of the respective radii.

$$\begin{cases}(r-r_0)^2=x^2+y^2\\(r-r_1)^2=(x-x_1)^2+(y-y_1)^2\\(r-r_2)^2=(x-x_2)^2+(y-y_2)^2.\end{cases} \tag1$$

Now, subtracting these equations in pairs,

$$\begin{cases}2r(r_1-r_0)+(r_1^2-r_0^2)=2xx_1+2yy_1 -x_1^2-y_1^2\\2r(r_2-r_0)+(r_2^2-r_0^2)=2xx_2 +2yy_2-x_2^2-y_2^2.\end{cases} \tag2$$

This system is linear and you can solve for $$x,y$$ in terms of $$r$$,

$$\begin{cases}x=ar+b\\y=cr+d.\end{cases} \tag3$$

Plug this in the first equation and get the quadratic

$$(r-r_0)^2=(ar+b)^2+(cr+d)^2. \tag4$$

Note that this gives you for the same "price" the construction of the circumcircle of three points, by setting $$r_0=r_1=r_2=0$$.

$$\begin{cases}0=2xx_1+2yy_1 -x_1^2-y_1^2\\0=2xx_2 +2yy_2-x_2^2-y_2^2.\end{cases}$$

$$r^2=b^2+d^2=x^2+y^2.$$

• Disclaimer - my maths is rusty :) . In your first step, isn't the distance between the centre of the searched circle, and any of the other centres, the sum of the radii (and not the difference)? – youcantryreachingme Feb 8 at 3:21
• @youcantryreachingme: no. – Yves Daoust Feb 8 at 8:31
• Could you help me understand please? If I have two circles touching each other, surely the distance between centres is r1 + r2? From centre 1 to the circumference = r1, then from that point on the second circle's circumference to its centre is r2. – youcantryreachingme Feb 9 at 2:45
• @youcantryreachingme: what did you mean by "the calculated circle must lie externally to the three known circles" ? – Yves Daoust Feb 9 at 12:44
• Imagine these were all coins - they must touch at their edges but not lie on top of one another. – youcantryreachingme Feb 9 at 21:00

$$(x-a)^2+(y-b)^2=r^2$$ $$(x-c)^2+(y-d)^2=s^2$$ $$(x-e)^2+(y-f)^2=t^2$$ from 1st and second circle Let P(x,y) be a general point and circumscribing circle has radius k C1 be the center of first circle and so on C2,C3 now when you draw any such circle circumscribing it you have a property that suggests P to C1 distance $$d_1 = k - r$$ P to C2 distance $$d_2= k - s$$ now difference of distance is $$d_1-d_2=s-r$$ which is a constant and basic definition of hyperbola suggests this only. now write equation for it $$\sqrt{(x-a)^2+(y-b)^2}-\sqrt{(x-c)^2+(y-d)^2}=s-r$$ as in your case s>r similarly get other equation as $$\sqrt{(x-a)^2+(y-b)^2}-\sqrt{(x-e)^2+(y-f)^2}=t-r$$ now solve these above 2 equations to get the center of circle now pick any of the circle say C2 of radius s, then distance between this calculated center and center of circle C2 added to the s gives the radius of the circle

you will get your answer as given below https://www.desmos.com/calculator/w0fnc0xeqd