求两个圆的面积,有可能重合,相交等。。
求出相交四边形面积,加两个扇形面积
#include<cstdio>
#include<iostream>
#include<cmath>
#define w 3.1415926
using namespace std;
double x,y,r,x2,y2,r2,ans;
int T;
double ask(double x,double y,double x2,double y2){
return sqrt((x-x2)*(x-x2)+(y-y2)*(y-y2));
}
int main(){
scanf("%d",&T);
while(T--)
{
ans=0;
scanf("%lf%lf%lf%lf%lf%lf",&x,&y,&r,&x2,&y2,&r2);
double t=ask(x,y,x2,y2);
if(t<r+r2&&t>abs(r-r2)){
double cosa=(t*t+r*r-r2*r2)/(2*t*r);
double cosb=(t*t+r2*r2-r*r)/(2*t*r2);
double a=acos(cosa);
double b=acos(cosb);
ans+=(w-a)*r*r;
ans+=(w-b)*r2*r2;
ans+=t*(r*sin(a)+r2*sin(b))/2;
}
else if(t>=r+r2){
ans+=w*r*r;
ans+=w*r2*r2;
}
else
ans+=max(r,r2)*max(r,r2)*w;
printf("%.3lf\n",ans);
}
}