Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import geometry;
- import patterns;
- size(9cm,0);
- line[] tan2cir(circle c1, circle c2){ line[] lines;
- if ( c1.C == c2.C && c1.r == c2.r ) { label( "Ups, circles are equal!", c1.C ); }
- if ( c1.C != c2.C ) {
- line[] n = { line(c1.C, c2.C) + unit(c2.C-c1.C) * dir(90) * c1.r, line(c1.C, c2.C) + unit(c1.C-c2.C) * dir(90) * c1.r };
- lines.append( n );
- if ( c1.r != c2.r ) { lines = tangents( circle( c1.C, c1.r ), scale( c2.r / (c2.r - c1.r), c2.C) * c1.C ); }
- lines.append( tangents( circle( c1.C, c1.r ), scale( c2.r / (c2.r + c1.r), c2.C) * c1.C ) ); }
- return lines;
- }
- /*
- // Код для проверки работоспособности
- real r = 3, R = 8, L = r + R + 4;
- // real L = 0; // для совпадения центров окружностей
- point O1 = (2,3), O2 = O1 + L * dir( 120 );
- circle c1 = circle( O1, r );
- circle c2 = circle( O2, R );
- line[] out = tan2cir( c1, c2 );
- draw( c1^^c2 );
- draw( out );
- label( "number of tangents is " + string( out.length ), c1.C, S ); // Размер массива касательных
- // Нерабочий код
- line[] tan2cir(circle c1, circle c2){ line[] lines;
- if ( c1.C == c2.C && c1.r == c2.r ) { label( "Ups, circles are equal!", c1.C ); }
- else { lines = { line(c1.C, c2.C) + unit(c2.C-c1.C) * dir(90) * c1.r, line(c1.C, c2.C) + unit(c1.C-c2.C) * dir(90) * c1.r };
- if ( c1.r != c2.r ) { lines = tangents( circle( c1.C, c1.r ), scale( c2.r / (c2.r - c1.r), c2.C) * c1.C ); }
- lines.append( tangents( circle( c1.C, c1.r ), scale( c2.r / (c2.r + c1.r), c2.C) * c1.C ) ); }
- return lines;
- }
- // Старый код, для сравнения прогресса
- line[] tan2cir(point O1, real r1, point O2, real r2){
- line[] lines;
- circle c1 = circle( O1, r1 );
- if ( r1 == r2 ) {
- line per = parallel(O1, dir(90) * line(O1, O2) );
- lines.push( parallel( intersectionpoints( c1, per )[0], line(O1, O2) ) );
- lines.push( parallel( intersectionpoints( c1, per )[1], line(O1, O2) ) );
- } else {
- point A = (O2 + (O1 - O2) * ( r2 / (r2 - r1) ) );
- lines.push( tangents(c1, A)[0] );
- lines.push( tangents(c1, A)[1] );
- }
- point B = (O2 - O1) * r1 / (r1 + r2);
- line[] tang = tangents( c1, B );
- for ( int i = 0; i < tang.length; ++i ) { lines.push( tang[i] ); }
- return lines;
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement