求相交圆面积

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#define Pi acos(-1.0)
using namespace std;

const double eps=1e-8;

struct point {
	double x,y;
};

double dist(point a,point b) //求两点间距离 
{
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

double area(point c1,double r1,point c2,double r2)//求相交圆面积 
{
	double d=dist(c1,c2);
	if(r1+r2<d+eps) return 0;
	if(d<fabs(r1-r2)+eps)
	{
		double r=min(r1,r2);
		return Pi*r*r;
	}
	double t1=acos((d*d+r1*r1-r2*r2)/(2*d*r1));
	double t2=acos((d*d+r2*r2-r1*r1)/(2*d*r2));
	return r1*r1*t1+r2*r2*t2-d*r1*sin(t1);//扇形面积: α/2*r*r
}

你可能感兴趣的:(求相交圆面积)