houseofmath

Common Tangents v2.0

Jan 24th, 2026 (edited)
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Asymptote 1.10 KB | Source Code | 0 0
  1. import geometry;
  2. import patterns;
  3. line[] CommonTangents(circle C1, circle C2)
  4. {
  5.   line[] L;
  6.   pair O1=C1.C, O2=C2.C;
  7.   real eps=1e-15;
  8.   real r1=C1.r, r2=C2.r, d=length(O2-O1), dr=abs(r1-r2), s=r1+r2;
  9.   if (d<eps && abs(r1-r2)<eps){
  10.     write("Окружности совпадают!");
  11.     return L;
  12.   }
  13.   if (d<eps){
  14.     write("Общих касательных нет.");
  15.     return L;
  16.   }
  17.   if (d+eps<dr){
  18.     write("Общих касательных нет.");
  19.     return L;
  20.   }
  21.   else if (abs(r1-r2)<eps){
  22.         pair u=unit(O2-O1);
  23.         pair n=(-u.y,u.x);
  24.         L.push(line(O1+n*r1, O2+n*r2));
  25.         L.push(line(O1-n*r1, O2-n*r2));
  26.         } else {
  27.           pair P = (r2*O1-r1*O2)/(r2-r1);
  28.           L.append(tangents(C2, P));
  29.           }
  30.   if (d+eps<s){}
  31.   else {
  32.   pair Q=(r2*O1+r1*O2)/(r1+r2);
  33.   L.append(tangents(C2, Q));
  34.   }
  35. return L;
  36. }
  37.  
  38. size(9cm,0);
  39. dotfactor=3;
  40. real r=1, R=2;
  41. point O1=(0,0), O2=4*dir(0);
  42. circle c1=circle(O1,r);
  43. circle c2=circle(O2,R);
  44. draw(c1);dot(O1);
  45. draw(c2, red);dot(O2, red);
  46.  
  47. line[] out=CommonTangents(c1,c2);
  48. draw(out, 0.25pt+gray);
  49. addMargins(5mm,5mm);
Advertisement
Add Comment
Please, Sign In to add comment