Apollonius circle calculation

1st circle :Radius R1
distance a
 
2nd circle :Radius R2
distance h
 
3rd circle :Radius R3
distance b

 

Method

Let (x, y) the coordinates of center for the searched circle, with radius R.
(-a, 0) coordinates of circle with radius R1
(0, -h) coordinates of circle with radius R2
(b, 0) coordinates of circle with radius R3

Distance from center to center of first circle : (R + R1)² = (x + a)² + y² or
R² - x² - y² = 2ax - 2R1R - R1² + a²   [1]
Distance to center of 2nd circle : (R - R2)² = x² + (y + h)² ou
R² - x² - y² = 2hy + 2R2R - R2² + h²   [2]
Distance to center of 3rd circle : (R + R3)² = (x - b)² + y²
R² - x² - y² = -2bx - 2R3R - R3² + b²   [3]

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

Difference [1] - [3] gives : 2ax - 2R1R - R1² + a² + 2bx + 2R3R + R3² - b² = 0 that is :
2(a + b)x = 2(R1 - R3)R + R1² - R3² + b² - a²   [4]
Or x = PR + Q with P = (R1 - R3)/(a + b) and Q = 0.5 × (R1² - R3² + b² - a²) / (a + b)

Difference [1] - [2] gives : 2ax - 2R1R - R1² + a² - 2hy - 2R2R + R2² - h² = 0 or
2hy = -2(R1 + R2)R + 2ax - R1² + R2² + a² - h²

Substituting x from [4] into [5] gives y = UR + V with
U = (aP - R1 - R2) / h and V = (2aQ - R1² + R2² + a² - h²) / 2h

Substituting then x and y into equation [2] results into a 2nd degree equation in R :
(R - R2)² = (PR + Q)² + (UR + V + h)² or
sR² + 2mR + n = 0 with
s = P² + U² - 1
m = PQ + U(V + h) + R2
n = Q² + (V + h)² - R2²

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 R1, R2, R3.
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 !

 

Home Arithmetic Geometric Misc Topics Scripts Games Exercices Mail Version Franšaise Previous topic Next topic