# Generate a circle centered on a line and touching 2 other circles

I'm working on an art project where I have a set of circles. I grow each circle around its center until it touches another circle. Once 2 circles touch, the point of contact remains fixed and they grow away from each other.

Now I'm working on dealing with 1 circle touching 2 others. Once they are actually touching, I can continue to grow them properly, but finding the proper parameters to get them to touch at exactly one point is proving tricky for me.

What's happening is that 2 circles are growing apart from one another. I expand the radius of one of them (and move it's center), but find that it's now overlapping a 3rd circle (that is, it intersects the 3rd circle at 2 points instead of 1). I'd like to back off the center and radius until it's touching the 3rd circle at exactly 1 point while still touching the 2nd circle at exactly 1 point.

Here are some pictures to make it more clear. Circle A is stationary at the moment, Circle B has just been expanded, and it now overlaps Circle C. I'd like to move Circle B's center along line AB and change its radius until it just touches Circle A and Circle C at a single point each.

How can I do that? I feel like there's some system of equations I could solve to find the proper center and radius, but my attempts at creating the proper system of equations always end up with 2 equations and 3 unknowns.

The circles can be of arbitrary size and may not be as nearly equally sized as in the above image.

We are looking for a circle centered on the given straight line (blue), and touching two given circles (blue). [] If $$A$$ and $$C$$ are centers of the given circles, $$a$$ and $$c$$ their radii, $$K$$ the center and $$r$$ the radius of a touching circle, then $$||KC|-|KA||=|r\pm c-(r\pm a)|=|c-a|.$$ The difference of distances of $$K$$ to two fixed points is constant. Therefore, the locus of centers of touching circles is a hyperbola with foci $$A$$ and $$C.$$ (See also this question.)
One vertex of the hyperbola is $$I,$$ it lies on $$AC$$ at equal distance to both blue circles.
Assume circles A and B (with centers $$(x_A, y_A)$$ and $$(x_B, y_B)$$ and radii $$r_A$$ and $$r_B$$) are tangent to each other and circle B is not yet tangent to circle C (with center $$(x_C, y_C)$$ and radius $$r_C$$). Let point T $$(x_T, y_T)$$ be the point of intersection between circles A and B. Points on the line connecting the center of B with point T would then have the equation $$(x,y) = (x_T,y_T) + k(x_B-x_T,y_B-y_T)\tag{1}$$ The radius of a circle with its center on that line and passing through point T is $$r= \sqrt{(x_T-x)^2+(y_T-y)^2} = k\cdot r_B\tag{2}$$ when you work out the algebra.
The distance d from a point on that line to the center of circle C is $$d= \sqrt{(x_C-x)^2+(y_C-y)^2}\tag{3}$$ Now, what we are looking for is the value of $$k$$ for which $$d=r+r_C = k\cdot r_B + r_C \tag{4}$$ Setting equations $$3$$ and $$4$$ equal to each other and slogging through the algebra gives the following answer $$k = \frac{(x_C-x_T)^2+(y_C-y_T)^2-r_C^2}{2((x_B-x_T)(x_C-x_T)+(y_B-y_T)(y_C-y_T)+r_Br_C))}$$ Inserting this value of $$k$$ into equations $$1$$ and $$2$$ will give you the new center of circle B and its radius.