# Coordinates of circle center on a line through a point touching other circle

I need to make a part of a program in java that calculates a circle center. It has to be a circle through a given point that touches another circle, and the variable circle center has the possibility to move over a given line.

Here the coordinates of A, B and C and the radius of the circle around A are given. I need to know how to get the coordinates of P and P' when they touch the blue circle around A.

A strong hint, but not a complete solution

Let \newcommand{\bu} {{\mathbf u}} \newcommand{\bv} {{\mathbf v}} \begin{align} s &= \|B - C\|\\ \bu &= \frac{B - C}{s} \end{align} The point $$P$$ is then $$C + t\bu$$ for some $$t \in \Bbb R$$, and I'll follow the picture and consider the case $$t < s$$ so that we find $$P$$ instead of $$P'$$. We'll work out some constraints on $$t$$.

The first constraint is that the distance from $$P$$ to $$B$$ (namely $$s - t$$), which is the radius of the circle around $$P$$, must, when added to $$r$$, the radius of the blue circle, give the distance from $$P$$ to $$A$$. Thus:

$$(s - t) + r = \| A - (C + t \bu) \|.$$ Squaring both sides, and letting $$\bv = A - C$$ and $$e = \|A - C \| = \|\bv\|$$, we get \begin{align} (s - t)^2 + 2r(s-t) + r^2 &= \| (A - C) - t \bu) \|^2\\ (s - t)^2 + 2r(s-t) + r^2 &= [ (A - C) - t \bu) ] \cdot [ (A - C) - t \bu) ] \\ s^2 - 2st + t^2 + 2rs-2rt + r^2 &= (A - C)\cdot(A-C) - 2t \bu \cdot (A - C) + t^2 \bu \cdot bu \\ s^2 - 2st + t^2 + 2rs-2rt + r^2 &= (A - C)\cdot(A-C) - 2t \bu \cdot (A - C) + t^2 & \text{, because \bu is a unit vector}\\ s^2 - 2st + t^2 + 2rs-2rt + r^2 &= e^2 - 2t \bu \cdot \bv + t^2 & \text{, defn's of \bv and e}\\ s^2 - 2st + 2rs-2rt + r^2 &= e^2 - 2t \bu \cdot \bv & \text{algebra}\\ 2t \bu \cdot \bv - 2st -2rt &= e^2 -s^2 -2rs - r^2& \text{algebra}\\ t( -2 \bu \cdot \bv + 2s + 2r) &= (s+r)^2 - e^2& \text{algebra}\\ t &= \frac{(s+r)^2 - e^2}{-2 \bu \cdot \bv + 2s + 2r }& \text{algebra}\\ \end{align} ...so that gives you the point $$P$$ (you just compute $$P + t\bu$$). Now you have to do the same thing, but starting with $$(t - s) + r = ...$$ to find the point on the other side of $$B$$.

Here is (not pretty) Matlab code to implement this, and a plot of the result of

circles([0 3], [1, 1], [-3, 0], 1)


being run in the Command window.

function circles(a, b, c, r)
clf;
a = a(:); b = b(:); c = c(:);

vv = b - c;
s = sqrt(dot(vv, vv));
u = (b-c)/s;

v = a - c;
e = sqrt(dot(v, v));
numerator = (s+r)^2 - e^2;
denominator = -2 * dot (u, v)+ 2*s + 2*r;
t = numerator/denominator;
P = c + t*u
% draw line from C to B
point(c);
point(b);
plot([c(1) b(1)], [c(2) b(2)], 'k');
circle(a, r);
circle(P, (s-t));
axis equal
figure(gcf);

function point(pt)
hold on;
plot(pt(1), pt(2), 'ro');
hold off;

t = linspace(0, 2*pi, 100);
x = ctr(1) + radius * cos(t);
y = ctr(2) + radius * sin(t);
hold on;
plot(x, y);
point(ctr);
hold off;


The blue circle is the one around point $$A$$; the red-orange circle is the computed on. The black line segment goes from $$C$$ to $$B$$.

Of course, you still have to work through the case where $$t > s$$ to find the coordinates of the center $$P'$$ and the radius of the second circle.

• Edited to fix a sign-error, and to add working code. – John Hughes Feb 8 '19 at 18:01

Geometric solution

Locus of points equidistant to a circle and a point (exterior to the circle) is a hyperbola.
These equidistant points are centers of circles through the given point, and touching the given circle.

In the present case, the given blue circle is denoted $$\gamma$$ and is centered at $$A.$$ The hyperbola has foci $$A$$ and $$B$$ and passes through the middle point of the segment $$BG,$$ where $$G$$ is intersection of $$AB$$ and $$\gamma.$$
Since the centers of circles touching $$\gamma$$ must lie at $$BC,$$ they are at the intersection of $$BC$$ and the hyperbola.

The picture gives two possible configurations assuming that $$BC$$ has empty intersection with the circle:

1. the line cuts each branch of the hyperbola at a single point
2. the line cuts one branch of hyperbola at two points

(analytic solution can be added à la commande)

• Very nice! Much better than my analytical solution. – John Hughes Feb 7 '19 at 20:52
• Thanks for your answer. I, however, can't see how I could make this into a fomula that gives the coordinates of the two points. Could you please give the analytic solution? – Floris Feb 8 '19 at 16:49
• @Floris as I see, John Hughes implemented a code in Matlab. If his answer is more appropriate to your needs, feel free to unaccept the mine and accept that of John. – user376343 Feb 8 '19 at 20:27

You haven’t mentioned this explicitly, but from the illustration is appears that you’re only interested in externally tangent circles. If the radius of the circle is $$r$$, then the points you are looking for satisfy $$|PA|-|PB|=r$$. Set $$P = (1-t)B+tC$$ and use the distance formula to get a somewhat messy-looking equation in $$t$$. You can find some useful suggestions for how to manipulate equations involving sums of radicals into a more manageable form in the answers to this question.