Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import geometry;
- import patterns;
- line[] CommonTangents(circle C1, circle C2)
- {
- line[] L;
- pair O1=C1.C, O2=C2.C;
- real eps=1e-15;
- real r1=C1.r, r2=C2.r, d=length(O2-O1), dr=abs(r1-r2), s=r1+r2;
- if (d<eps && abs(r1-r2)<eps){
- write("Окружности совпадают!");
- return L;
- }
- if (d<eps){
- write("Общих касательных нет.");
- return L;
- }
- if (d+eps<dr){
- write("Общих касательных нет.");
- return L;
- }
- else if (abs(r1-r2)<eps){
- pair u=unit(O2-O1);
- pair n=(-u.y,u.x);
- L.push(line(O1+n*r1, O2+n*r2));
- L.push(line(O1-n*r1, O2-n*r2));
- } else {
- pair P = (r2*O1-r1*O2)/(r2-r1);
- L.append(tangents(C2, P));
- }
- if (d+eps<s){}
- else {
- pair Q=(r2*O1+r1*O2)/(r1+r2);
- L.append(tangents(C2, Q));
- }
- return L;
- }
- size(9cm,0);
- dotfactor=3;
- real r=1, R=2;
- point O1=(0,0), O2=4*dir(0);
- circle c1=circle(O1,r);
- circle c2=circle(O2,R);
- draw(c1);dot(O1);
- draw(c2, red);dot(O2, red);
- line[] out=CommonTangents(c1,c2);
- draw(out, 0.25pt+gray);
- addMargins(5mm,5mm);
Advertisement
Add Comment
Please, Sign In to add comment