1 #include<iostream> 2 #include<numeric> 3 #include<iomanip> 4 #include<algorithm> 5 #include<cmath> 6 using namespace std; 7 8 int main() 9 { 10 //freopen("acm.acm","r",stdin); 11 double x1; 12 double y1; 13 double r1; 14 double x2; 15 double y2; 16 double r2; 17 double A; 18 double B; 19 double d; 20 double s; 21 double area; 22 while(cin>>x1>>y1>>r1>>x2>>y2>>r2) 23 { 24 d = sqrt((x1 - x2)*(x1 - x2)+(y1 - y2)*(y1 - y2)); 25 if(r1 < r2) 26 iter_swap(&r1,&r2); 27 if(d >= r1+r2) 28 { 29 cout<<setiosflags(ios::fixed)<<setprecision(3)<<0.0<<endl; 30 return 0; 31 } 32 if(d <= r1-r2) 33 { 34 cout<<setiosflags(ios::fixed)<<setprecision(3)<<r2*r2*2.0*acos(0.0000000)<<endl; 35 return 0; 36 } 37 A=acos((r2*r2+d*d-r1*r1)/2/r2/d);//相交 38 B=acos((r1*r1+d*d-r2*r2)/2/r1/d); 39 s=(r1+r2+d)/2; 40 s=sqrt(s*(s-r1)*(s-r2)*(s-d)); 41 area=r1*r1*B+r2*r2*A-2*s; 42 cout<<setiosflags(ios::fixed)<<setprecision(3)<<area<<endl; 43 } 44 } 45 46 47 48 49 50 51 /* 52 分为两部分扇形来求: 53 设两圆圆心分别为O1,O2,交点为E,F, 54 设两圆半径分别为r1,r2,圆心距为d,则O1E=r1,O2E=r2,O1O2=d, 55 由此可求得三角形EO1O2面积S,以及∠EO1O2的度数α,∠EO2O1度数β, 56 公式为:三角形ABC中,a^2=b^2+c^2-2bc*cosA,具体的计算不用我说了吧. 57 最后阴影部分面积为α*r1^2+β*r2^2-2S. 58 */
时间: 2024-10-14 21:06:49