# How can I only draw outer common tangent to two circles?

I have code worked for drawing common tangent lines to two circles(http://en.wikipedia.org/wiki/Tangent_lines_to_circles), now I want to delete the inner common tangent lines, how?

Manipulate[Block[{t1, t2, v1, v2, pts},
t1 = {xm, ym};
t2 = {xn, yn};
{v1, v2} = p;
pts = {t1, t2} /. NSolve[{(t2 - v2).(t2 - t1) == 0, (t1 - v1).(t2 - t1) == 0,
(t1 - v1).(t1 - v1) == r1^2, (t2 - v2).(t2 - v2) == r2^2}, {xm, ym, xn, yn}, Reals];
If[pts == {t1, t2}, pts = {}];
Graphics[{Circle[v1, r1], Circle[v2, r2], Line[pts]},
PlotRange -> 6, Frame -> 1]
], {{p, {{-3, 1}, {3, 0}}}, Locator}, {{r1, 1}, 1, 3}, {{r2, 2}, 1,
3}]


-

Here is one way:

  Manipulate[Block[{t1, t2, v1, v2, pt, pts}, t1 = {xm, ym};
t2 = {xn, yn};
{v1, v2} = p;
pt = {t1, t2} /.
NSolve[{(t2 - v2).(t2 - t1) == 0, (t1 - v1).(t2 - t1) == 0,
(t1 - v1).(t1 - v1) == r1^2, (t2 - v2).(t2 - v2) == r2^2}, {xm,
ym, xn, yn}, Reals];
pts = Select[pt, Sign[(#[[1]] - v1).(#[[2]] - v2)] == 1 &];
If[pts == {t1, t2}, pts = {}];
Graphics[{Circle[p[[1]], r1], Circle[p[[2]], r2], Line@pts},
PlotRange -> 6, Frame -> 1]], {{p, {{-3, 1}, {3, 0}}},
Locator}, {{r1, 1}, 1, 3}, {{r2, 2}, 1, 3}]


EDIT: Pickett's suggestion

Putting constraint in NSolve:

  Manipulate[Block[{t1, t2, v1, v2, pts}, t1 = {xm, ym};
t2 = {xn, yn};
{v1, v2} = p;
pts = {t1, t2} /.
NSolve[{(t2 - v2).(t2 - t1) == 0, (t1 - v1).(t2 - t1) ==
0, (t1 - v1).(t1 - v1) == r1^2, (t2 - v2).(t2 - v2) ==
r2^2, (t1 - v1).(t2 - v2) > 0}, {xm, ym, xn, yn}, Reals];
If[pts == {t1, t2}, pts = {}];
Graphics[{Circle[p[[1]], r1], Circle[p[[2]], r2], Line[pts]},
PlotRange -> 6, Frame -> 1]], {{p, {{-3, 1}, {3, 0}}},
Locator}, {{r1, 1}, 1, 3}, {{r2, 2}, 1, 3}]

-
+1, you could also add (t1 - v1).(t2 - v2) > 0 in the equation system. – C. E. Aug 23 '14 at 11:54
@Pickett thanks...that would have perhaps been simpler... – ubpdqn Aug 23 '14 at 11:56
Manipulate[Block[{x1, y1, x2, y2},
{{x1, y1}, {x2, y2}} = p;
Show[Graphics[{Circle[{x1, y1}, r1], Circle[{x2, y2}, r2]},
PlotRange -> 6, Frame -> 1],
ContourPlot[
r1^2*((x - x2)^2 + (y - y2)^2) -
2*r1*r2*((x - x1)*(x - x2) + (y - y1)*(y - y2)) +
r2^2*((x - x1)^2 + (y - y1)^2) - (-x*y1 + x*y2 + x1*y - x1*y2 -
x2*y + x2*y1)^2 == 0, {x, -6, 6}, {y, -6, 6},
PerformanceGoal -> "Quality"]]], {{p, {{-3, 1}, {3, 0}}},
Locator}, {{r1, 1}, 1, 3}, {{r2, 2}, 1, 3}]


-