# Connecting two tangents with two circles of equal radius

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).

-
From what you write it doesn't appear to be clear what you want. And if you want what I think you do then your problem doesn't have a solution. Maybe you can clarify: You have two given line segments with endpoints $p_i$ and $d_i$ respectively. Now you want two circles of the same radius such that... right? – Simon Markett May 24 '12 at 9:52
@Simon: Sorry it isn't very clear. p1 and p2 are the end and start points of two directed line segments. d1 and d2 are unit vectors perpendicular to the direction of the line segments (perpendicular in opposite directions, so d1 is 90 degrees to the right of the line ending at p1, and d2 is 90 degrees to the left of the line that starts at p2, or vice versa). I'm reasonably sure that if p2 is rotationally right of the line ending at p1 then d1 should be to the right of this line also for the optimal solution, otherwise it is to the left. – Byker Dave May 24 '12 at 10:34
It's still not very clear, $p_1$ and $p_2$ are start end point of both lines? Or do you mean: you have two lines parallel to the $x$-axis (or line segments, but this should change your situation) passing through $(0,0)$ and $(5,2)$, respectively. Now you want two circles of equal radius such that the first line touches the first circle in $(0,0)$, the second line touches the second circle in $(5,2)$ and the two circles touch in one point? – Simon Markett May 24 '12 at 10:46

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$.