View Code of Problem 106

#include<iostream>
#include<cmath>
using namespace std;
int main() {
	double x1,y1,x2,y2,r,d,s1,s3,s;
	while(cin>>x1>>y1>>x2>>y2>>r) {
		d=sqrt(pow(x1-x2,2)+pow(y1-y2,2));//圆心距
		if(2*r<d) cout<<"相离"<<endl;
		else if(2*r==d) cout<<"相切"<<endl;
		else {//2*r>d 相交或者重合 
			if(d==0) cout<<"重合"<<endl; 
			else {
				double ao1b=acos(d/(2*r));//∠ao1b=∠ao2b 
				s1=r*r*ao1b;//s1=s2 弧Ao1B的面积 
				s3=r*d*sin(ao1b)/2;//△Ao1o2的面积 
				s=s1*2-2*s3;
				cout<<"相交 ";
				printf("%.2f\n",s);
			}
		}
	}
} 

Double click to view unformatted code.


Back to problem 106