View Code of Problem 106

#include<stdio.h>
#include<math.h> 
#define PI 3.141592535 
int main()
{
	double x1,y1,x2,y2;
	double r;		// 数学:0<d<2r 相交;0 重合;>2r相离;=2r相切; 
	while(scanf("%lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&r)!=EOF)
	{
		double d;
		d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
		if(d==0)
			printf("重合\n");
		else if(d>2*r) 
			printf("相离\n");
		else if(d==2*r)
			printf("相切\n");
		else
		{
			double h=sqrt(r*r-(d/2)*(d/2));
			double st=h*d/4;	//s=h*d/2*1/2; 大三角形面积 
			double sr=atan(h/d*2)/(2*PI)*(PI*r*r);
			printf("相交 %.2lf\n",(sr-st)*4);
		}
		
	}
}

Double click to view unformatted code.


Back to problem 106