View Code of Problem 106

#include<iostream>
#include<cmath>
using namespace std;
int main(){
	double x1,y1,x2,y2,r;
	while(cin>>x1>>y1>>x2>>y2>>r){
		if(x1==x2&&y1==y2){
			cout<<"重合"<<endl;
		} 
		else{
			double distance=(sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
			if(2*r<distance){
				cout<<"相离"<<endl;
			}
			else if(2*r==distance){
				cout<<"相切"<<endl;
			}
			else{
				double a;
				a=2.0*acos(distance/(r*2));	//求角度 ,返回类型为弧度制 
				double s=(a*r*r)-(r*r*sin(a));//扇形面积-菱形面积 
				printf("相交 %.2lf\n",s); 
			}
		}
	}
} 

Double click to view unformatted code.


Back to problem 106