View Code of Problem 106

#include<stdio.h>
#include<math.h>
void main(){
  float x1,x2,y1,y2,r;
  while(scanf("%f %f %f %f %f",&x1,&y1,&x2,&y2,&r)!=EOF){
    float d1=sqrt(pow((x2-x1),2)+pow((y2-y1),2));
    float d2=2*r;
    if(x1==x2 && y1==y2){
      printf("重合\n");
    }else{ 
      if(d1==d2)
        printf("相切\n");
      else if(d1>d2)
        printf("相离\n");
      else{
          double angle = acos(d1*d1/(2*r*d1));
          printf("相交 %.2f\n",2*angle*r*r-r*d1*sin(angle));
      }
    }
  }
}

Double click to view unformatted code.


Back to problem 106