Calculating a tangent arc between two points on two circles

How can I calculate the arc between two circles? The arc must be tangent to the two points on the circles.

Here is a picture illustrating it. I'm trying to code and calculate the orange arc and the blue arc.

The points B, F, D, and E can be changed by the user and dynamically update.

-
Is AC supposed to be a circle arc? If it isn't, the question seems ill-posed. If it is, then the circles implied by those two arcs are concentric to the circle implied by AC, and it should be straightforward to figure out what their radii are. –  Guess who it is. Nov 4 '10 at 22:24
I don't think that it necessarily HAS to be a circle, but I'm thinking that it might only be possible to calculate them if the arcs are part of a bigger circle. Do you know how to calculate it in that case? –  Russell Strauss Nov 4 '10 at 22:44
I don't think BE can be a circular arc in general. You have four constraints (2 incidence and 2 tangency), but a circle is defined by only three. In particular, imagine if the user moved point E to coincide with point D -- what could the arc BE look like? –  Rahul Nov 4 '10 at 22:51
On the other hand, if you are okay with specifying only one of the two points (i.e. if the user moves B, E moves correspondingly), then there is a solution as a circular arc. –  Rahul Nov 4 '10 at 23:04
If points F, E, B, and D are meant to be independent, then there is no reason to expect that they be circle arcs. You can however construct a cubic segment, since each segment has to satisfy four constraints: two points to pass through and the corresponding slopes at those points, and a cubic is uniquely determined by four parameters. –  Guess who it is. Nov 5 '10 at 10:57

As others have mentioned in comments, your control points cannot be independent. Nevertheless, if we assume that a given configuration has the properties you want, we can analyze the geometry.

I'll consider the orange arc, $BE$, and I'll assume that both circles $A$ and $C$ overlap the interior of the orange circle, which I'll further assume has not degenerated into a line.

Let $a = |AB|$, $c = |CE|$, and $x=|AC|$; all of these can be considered known quantities. Let the (unknown) radius of the orange circle be $r = |PB| = |PE|$, where $P$ is the circle's center. Because radii $AB$ and $PB$ are perpendicular to a common tangent line at $B$, these segments lie on the same line; likewise for $CE$ and $PE$; consequently, $P$ lies at the intersection of the two extended radii $AB$ and $CE$, so that the angle $BPE$ is congruent to the angle between the vectors $AB$ and $CE$. Call the measure of that angle $\theta$; it, too, can be considered a known quantity.

Now, triangle $APC$ has sides of length $x$, $r-a$, and $r-c$ (the last two because of the assumed overlap of circles), with angle $\theta$ between the last two. By the Law of Cosines:

$$x^2 = (r-a)^2 + (r-c)^2 - 2 (r-a)(r-c) \cos\theta$$

Solve this quadratic equation for $r$, and you can calculate whatever else you need to know: arc length, location of $P$, equation of the orange circle, etc.

(The equation of the orange circle can be expressed in a form that degenerates into a line equation as $r$ approaches infinity. Note that, in such a degenerate case, $\theta = 0$.)

-

I'm going to ignore arc AC and address what determines arcs FD and BE based on the points A, B, C, D, E, and F.

If two circles with centers X and Y are tangent at P, then X, Y, and P are collinear. So, line AF and line CD both pass through the center of the circle containing arc FD and line AB and line CE both pass through the center of the circle containing arc BE.

If you have coordinates for all of these points, you can write equations of the line and algebraically find their points of intersection. Given the coordinates of the centers of the circles, you can determine their radii. Given the coordinates of the centers of the circles and the endpoints of the arcs, you can determine the measure of the central angles that subtend the arcs. From the radii and central angles, you can determine the arc lengths. (It's hard to be more specific without introducing a bunch of variables, but I can add more detail if you are not sure how to carry out any of these steps.)

-