View Code of Problem 106

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

Double click to view unformatted code.


Back to problem 106