
Two circles in a plane may have zero, one, two, three, or four common tangents, depending on how the circles overlap.
Find the equations of the (up to) four lines tangent to circles A and B, whose centers are (x_{A},y_{A}) and (x_{B},y_{B}) and whose radii are r_{A} and r_{B}.
The way I attack this problem is to note that each of the four tangent lines intersects at right angles a radius of circle A and a radius of circle B. Moreover, the radii of the two circles are oriented in the same direction, as they are both perpendicular to a single line. Even the radii that meet the two tangent lines that cross between the circles are considered to be oriented in the same direction; however one of them is treated as having negative length! In fact, this is how I will select the four tangent lines: using the four combinations of positive and negative radius length for the two circles.
The solution to this problem will give the equation of the tangent line (given one of the four combinations of positive and negative radii of the two circles) as
Ax + By + C = 0
The big challenge in this solution is to calculate the argument of the radii that meet each of the tangent lines, which I represent as θ. I tackle that right away, giving you A and B which are the cosine and sine of θ, respectively, in terms of the centers and radii of the two circles. In this way, by knowing the sine and cosine of θ, the quadrant is uniquely specified, and so it is possible to pick the right inverse sine and inverse cosine, and so θ is pinned down exactly.
Finally, we calculate C in terms of A, B, and the center and radius of one of the circles (it doesn't matter which circle, as it turns out), which completes the task.
Part 1: finding A and B, parameterized as A=cos θ and B=sin θ
The distance from a line of the form Ax+By+C=0 to a point (h,k) is Ah+Bk+C/sqrt(A^{2}+B^{2}) (proof), and the parameters A, B, C of the line can be scaled by dividing each one by sqrt(A^{2}+B^{2}) so that after they have been scaled, A^{2}+B^{2}=1. Then you can define θ so that A = cos θ, and B = sin θ.
Then the tangent lines, expressed as (cosθ)x+(sinθ)y+C=0, and parameterized by θ and C are the four solutions of:
x_{A} cos θ + y_{A} sin θ + C = r_{A}
and
x_{B} cos θ + y_{B} sin θ + C = r_{B}
Solving these equations for cosθ and sinθ isn't easy, but when we do, we get:
A = cosθ = ((x_{A}x_{B})(±r_{A}±r_{B}) + (y_{A}y_{B}) sqrt((x_{A}x_{B})^{2}+(y_{A}y_{B})^{2}(±r_{A}±r_{B})^{2}))/((x_{A}x_{B})^{2}+(y_{A}y_{B})^{2})
B = sinθ = ((y_{A}y_{B})(±r_{A}±r_{B})  (x_{A}x_{B}) sqrt((x_{A}x_{B})^{2}+(y_{A}y_{B})^{2}(±r_{A}±r_{B})^{2}))/((x_{A}x_{B})^{2}+(y_{A}y_{B})^{2})with the four solutions being the four possible combinations of ±r_{A}±r_{B} (allowing ±r_{A} and ±r_{B} to toggle independently). Each solution yields values of A=cosθ and B=sinθ for a tangent line Ax+By+C=0. When the radii have the same sign, the tangent is one of the pair of lines that cross between the circles. When they have opposite sign, the solution is for one of the outer tangents.
Part 2: finding C, which selects among many parallel lines the one line that's just the right distance from the centers of the two circles
To find C, since we know a point (h,k) on the line Ax+By+C=0, then C=(Ah+Bk). Now, observe that
(x_{B}±r_{B} cosθ, y_{B}±r_{B} sinθ)
is a point on the tangent line, so
C = (x_{B}cosθ±r_{B} cos^{2} θ + y_{B}sinθ±r_{B} sin^{2} θ), and simplifying cos^{2}+sin^{2},
C = (x_{B}cosθ+y_{B}sinθ±r_{B})You may wonder why I used circle B to identify a point on the tangent line. It turns out that circle A can be used, but you need to travel the other direction along the identified radius. That is,
(x_{B}±r_{B} cos θ, y_{B}±r_{B} sin θ) and
(x_{A}±r_{A} cos θ, y_{A}±r_{A} sin θ)are points on the same tangent line (for a given choice of signs of ±r_{A} and ±r_{B}). My choice of sign for cosθ and sinθ was arbitrary. Interchanging the roles of circle A and circle B results in assigning the opposite signs to cosθ, sinθ, and C.
Note regarding this solution: Although the derivation of solutions for cosθ and sinθ is not presented here, I'll show you how to verify the solution is correct. First square the expressions for cosθ and sinθ, add them together, and collect terms. You'll see it comes to one. That is, the numerator of this result factors as ((x_{A}x_{B})^{2}+(y_{A}y_{B})^{2})^{2}. Next, you can evaluate x_{A} cosθ+y_{A} sinθ+C and x_{B} cosθ+y_{B} sinθ+C to verify they are indeed r_{A} and r_{B}, respectively. Using C=(x_{B}cosθ+y_{B}sinθ±r_{B}), the second equation verifies easily. To verify the first, you need to show
x_{A} cosθ+y_{A} sinθ(x_{B}cosθ+y_{B}sinθ±r_{B})=±r_{A}, i.e.
(x_{A}x_{B})cosθ+(y_{A}y_{B})sinθ=±r_{A}±r_{B}.Again, it's rather tedious, but I've done it, and everything on the left hand side except ±r_{A}±r_{B} cancels, verifying the result.
www.mathhelpforum.com/mathhelp/calculus/26553calculatetangentline2circles.html was very helpful in developing this page, especially the post by TwistedOne151, which suggested using cosθ and sinθ to parameterize the A and B coefficients of the equation of the line.
Find the points of intersection of two circles
Find the equation of a circle, given three points
Heron's Formula for the area of a triangle, which gives an imaginary "area" for impossible triangles.
The webmaster and author of this Math Help site is Graeme McRae.