Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <string.h>
- #include <string>
- using namespace std;
- // macros
- #define MAX(A,B) ((A)>(B)?(A):(B))
- #define MIN(A, B) ((A)<(B)?(A):(B))
- #define S(X) ( (X) * (X) )
- #define ABS(X) ( ((X) < 0) ? -1*(X) : (X) )
- #define EPS 1e-4
- #define SIZE 100
- // value of Pi
- const double PI = acos(-1.0);
- // check double equality A == B
- bool isEqual(double A, double B){
- return (A-B) < EPS;
- }
- int main()
- {
- double g1,f1,r1,g2,f2,r2,d,x,y,g,f,y1,y2,x1,x2,a,b,h;
- while(scanf("%lf %lf %lf %lf %lf %lf",&g1,&f1,&r1,&g2,&f2,&r2)==6){
- d=sqrt((g1-g2)*(g1-g2)+(f1-f2)*(f1-f2));
- if(r1 == 0.00 && r2 == 0.00)
- {
- if(x1 == x2 && y1 == y2) printf("(%0.3lf,%0.3lf)\n",round(x1),round(y1));
- else printf("NO INTERSECTION\n");
- }
- else if(d==0 || d<=ABS(r1-r2)){
- //same inf
- printf("THE CIRCLES ARE THE SAME\n");
- }
- else if(d>r1+r2+EPS || d+EPS< ABS(r1-r2)){
- printf("NO INTERSECTION\n");
- }
- else if(fabs(d-r1+r2) < 1e-4 || fabs(d-r1-r2) < 1e-4){
- //touch
- x=(g1+g2)/2;
- y=(f1+f2)/2;
- printf("(%.3lf,-%.3lf)\n",(x+EPS),(y+EPS));
- }
- else if(d<r1+r2 ){
- //2 intersect
- a = (r1*r1 - r2*r2 + d*d ) / (2*d);
- h = sqrt(r1*r1 - a*a);
- g=g1+a*(g2-g1)/d;
- f=f1+a*(f2-f1)/d;
- x1=g+h*(f1-f2)/d;
- x2=g-h*(f1-f2)/d;
- y1=f+h*(g1-g2)/d;
- y2=f-h*(g1-g2)/d;
- if(x1<x2 || (x1==x2 && y1<y2))
- printf("(%0.3lf,%0.3lf)(%0.3lf,%0.3lf)\n",(x1+EPS),(y1+EPS),(x2+EPS),(y2+EPS));
- else
- printf("(%0.3lf,%0.3lf)(%0.3lf,%0.3lf)\n",(x2+EPS),y2+EPS,(x1+EPS),(y1+EPS));
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement