Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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}]

enter image description here

share|improve this question

2 Answers 2

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}]

enter image description here

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}]
share|improve this answer
1  
+1, you could also add (t1 - v1).(t2 - v2) > 0 in the equation system. –  Pickett Aug 23 at 11:54
    
@Pickett thanks...that would have perhaps been simpler... –  ubpdqn Aug 23 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}]

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.