Advertisement
Farjana_rimi

Untitled

Nov 26th, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <string.h>
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9. // macros
  10. #define MAX(A,B) ((A)>(B)?(A):(B))
  11. #define MIN(A, B) ((A)<(B)?(A):(B))
  12. #define S(X) ( (X) * (X) )
  13. #define ABS(X) ( ((X) < 0) ? -1*(X) : (X) )
  14. #define EPS 1e-4
  15. #define SIZE 100
  16.  
  17. // value of Pi
  18. const double PI = acos(-1.0);
  19.  
  20. // check double equality  A == B
  21. bool isEqual(double A, double B){
  22.         return (A-B) < EPS;
  23. }
  24.  
  25. int main()
  26. {
  27.     double g1,f1,r1,g2,f2,r2,d,x,y,g,f,y1,y2,x1,x2,a,b,h;
  28.     while(scanf("%lf %lf %lf %lf %lf %lf",&g1,&f1,&r1,&g2,&f2,&r2)==6){
  29.         d=sqrt((g1-g2)*(g1-g2)+(f1-f2)*(f1-f2));
  30.  
  31.         if(r1 == 0.00 && r2 == 0.00)
  32.         {
  33.             if(x1 == x2 && y1 == y2) printf("(%0.3lf,%0.3lf)\n",round(x1),round(y1));
  34.             else printf("NO INTERSECTION\n");
  35.         }
  36.  
  37.         else if(d==0 || d<=ABS(r1-r2)){
  38.             //same inf
  39.             printf("THE CIRCLES ARE THE SAME\n");
  40.         }
  41.         else if(d>r1+r2+EPS || d+EPS< ABS(r1-r2)){
  42.            printf("NO INTERSECTION\n");
  43.         }
  44.         else if(fabs(d-r1+r2) < 1e-4 || fabs(d-r1-r2) < 1e-4){
  45.             //touch
  46.             x=(g1+g2)/2;
  47.             y=(f1+f2)/2;
  48.             printf("(%.3lf,-%.3lf)\n",(x+EPS),(y+EPS));
  49.  
  50.         }
  51.         else if(d<r1+r2 ){
  52.             //2 intersect
  53.             a = (r1*r1 - r2*r2 + d*d ) / (2*d);
  54.             h = sqrt(r1*r1 - a*a);
  55.             g=g1+a*(g2-g1)/d;
  56.             f=f1+a*(f2-f1)/d;
  57.  
  58.             x1=g+h*(f1-f2)/d;
  59.             x2=g-h*(f1-f2)/d;
  60.  
  61.             y1=f+h*(g1-g2)/d;
  62.             y2=f-h*(g1-g2)/d;
  63.  
  64.             if(x1<x2 || (x1==x2 && y1<y2))
  65.                 printf("(%0.3lf,%0.3lf)(%0.3lf,%0.3lf)\n",(x1+EPS),(y1+EPS),(x2+EPS),(y2+EPS));
  66.             else
  67.                 printf("(%0.3lf,%0.3lf)(%0.3lf,%0.3lf)\n",(x2+EPS),y2+EPS,(x1+EPS),(y1+EPS));
  68.         }
  69.     }
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement