(-a, 0) coordinates of circle with radius R

(0, -h) coordinates of circle with radius R

(b, 0) coordinates of circle with radius R

Distance from center to center of first circle :
(R + R_{1})² = (x + a)² + y² or

R² - x² - y² = 2ax - 2R_{1}R - R_{1}² + a² [1]

Distance to center of 2^{nd} circle :
(R - R_{2})² = x² + (y + h)² ou

R² - x² - y² = 2hy + 2R_{2}R - R_{2}² + h² [2]

Distance to center of 3^{rd} circle :
(R + R_{3})² = (x - b)² + y²

R² - x² - y² = -2bx - 2R_{3}R - R_{3}² + b² [3]

All these equations are in the form : R² - x² - y² = Ax + By + CR

Difference [1] - [3] gives :
2ax - 2R_{1}R - R_{1}² + a² + 2bx + 2R_{3}R + R_{3}² - b² = 0
that is :

2(a + b)x = 2(R_{1} - R_{3})R + R_{1}² - R_{3}² + b² - a² [4]

Or x = PR + Q
with P = (R_{1} - R_{3})/(a + b) and
Q = 0.5 × (R_{1}² - R_{3}² + b² - a²) / (a + b)

Difference [1] - [2] gives :
2ax - 2R_{1}R - R_{1}² + a² - 2hy - 2R_{2}R + R_{2}² - h² = 0
or

2hy = -2(R_{1} + R_{2})R + 2ax - R_{1}² + R_{2}² + a² - h²

Substituting x from [4] into [5] gives y = UR + V with

U = (aP - R_{1} - R_{2}) / h and
V = (2aQ - R_{1}² + R_{2}² + a² - h²) / 2h

Substituting then x and y into equation [2] results into a 2^{nd} degree equation in R :

(R - R_{2})² = (PR + Q)² + (UR + V + h)²
or

sR² + 2mR + n = 0 with

s = P² + U² - 1

m = PQ + U(V + h) + R_{2}

n = Q² + (V + h)² - R_{2}²

If we choose different circles, we get generally a total of 8 solutions.

They are just obtained from the previous formulas with all possible signs
for R_{1}, R_{2}, R_{3}.

This would result into 16 solutions, but just keep one of the two solutions of the quadratic.

The previous calculations fail if a + b = 0 (circles 1 and 3 have same center)
or if h = 0 (inline centers).

Direct usage of previous formulas in a program could result into wrong results because of cumulated inacurracies.

This script doesn't care of these "pathological" cases.

JavaScript mandatory ! na !