[Math] Connecting two tangents with two circles of equal radius

circlesgeometry

In a cartesian system I have 2 lines (an input and an output) and want to find the radius (r) and centre (c1, c2) of the two circles of equal radius that are touched tangentially at the end point of the input line (p1) and the start point of the output line (p2), and touch each other tangentially. The desired outcome is that a smooth path will be possible from the input line, onto the first circle, onto the second circle where they touch and then onto the output line.

I got part way through a solution but failed: Assuming that I can work out the direction of the lines perpendicular to input/output lines (d1, d2) that the circles' centres should lie on to give the optimal (smallest radius) solution, I noted that sliding c1 and c2 along these lines by an amount (t) would give the correct result (t = r) when the distance between c1 and c2 was 2t.

c1 = p1 + t * d1
c2 = p2 + t * d2
|c1 c2| = 2t

This all seems correct to me, but my method of solving it from there involved making a quadratic equation and solving for t. For my simple test data (below) this resulted in a division by zero and taking the root of a negative number (it is possible that I expanded incorrectly, but have checked several times and can't find the error).

Sample data:

p1 = (0,0)
p2 = (5,2)
d1 = (1,0)
d2 = (-1,0)

I am looking for either a quadratic equation that works or an entirely different method of working it out, I'm just after a generalised solution (I can find a solution for the sample data through trig but I don't know of a trig method that generalises well).

Best Answer

Suppose we let $q_1$ and $q_2$ denote the centers of circles c1 and c2 respectively, and let $r$ denote their radii. We know that $$q_1 = p_1 + r*d_1$$ $$q_2 = p_2 + r*d_2$$ $$distance(q_1, q_2) = 2r$$ Substitute $q_1$ and $q_2$ from the first and second equations into the third, and you get a quadratic that you can solve to get $r$. Substitute back into the first and second equations to get $q_1$ and $q_2$.