两圆相离,外切,内切,内涵,很容易写,
相交的情况有有两种,但是方式是一样的,写成一样并不影响。
设半径R, 1.已知圆心角弧度α(或者角度n) 面积S=α/(2π)*πR²=αR²/2 S=(n/360)*πR² 2.已知弧长L: 面积S=LR/2
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const double PI=3.141592653;
struct point
{
double x,y;
double r;
};
double dis(point a,point b)
{
return sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) );
}
double fun(point a,point b) //求两圆的相交面积函数。
{
double d=dis(a,b);
if(d>=a.r+b.r) return 0;
double r=(a.r>b.r?b.r:a.r);
if( d<=fabs(a.r-b.r) ) return PI*r*r;
double A1=acos( (a.r*a.r+d*d-b.r*b.r)/2/a.r/d );
double A2=acos( (b.r*b.r+d*d-a.r*a.r)/2/b.r/d );
double res=A1*a.r*a.r + A2*b.r*b.r;
res-=sin(A1)*a.r*d;
return res;
}
int main()
{
point a,b;
while(~scanf("%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&a.r,&b.x,&b.y,&b.r))
{
double res=fun(a,b);
printf("%.3lf\n",res);
}
return 0;
}