View Code of Problem 106

#include<stdio.h>
#include<math.h>
int main()
{
	double x1,x2,y1,y2;
	double r;
	while(scanf("%lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&r)!=EOF)
	{
	//	if(x1>20||x2>20||y1>20||y2>20||r>20||x1<-20||x2<-20||y1<-20||y2<-20||r<-20)
	//	break;
			double x=x1-x2;
			double y=y1-y2;
			double l=sqrt(x*x-y*y);
		if(l==0)
		{
			printf("重合\n");
		}
			
		else if(l>2*r)
		{
				printf("相离\n");
		}
		else if(l==2*r)
		{
				printf("相切\n");
		}
		else
		{
				double ang1=acos((r*r+l*l-r*r)/(2*l*r));
				double ang2=acos((r*r+l*l-r*r)/(2*l*r));
				double area=ang1*r*r*2-sin(ang1)*r*l;
				printf("相交 %.2lf\n",area);
		}
	}
}

Double click to view unformatted code.


Back to problem 106