#include<stdio.h>
#include<iostream>
#include<iomanip>//这个库含有setprecision(15)的精度设置
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1,class T2>inline void gmax(T1 &a,T2 b){if(b>a)a=b;}
template <class T1,class T2>inline void gmin(T1 &a,T2 b){if(b<a)a=b;}
const int N=0,M=0,Z=1e9+7,ms63=1061109567;
const long double PI=acos(-1.0);
struct Round
{
long double x,y;
long double r;
long double K(long double x)
{
return x*x;
}
long double Dis(Round a,Round b)
{
return sqrt(K(a.x-b.x)+K(a.y-b.y));
}
long double Intersection_area(Round a,Round b)
{
long double dis=Dis(a,b);
if(a.r==0||b.r==0||dis>=a.r+b.r)return 0;
else if(dis<=fabs(a.r-b.r))return PI*K(min(a.r,b.r));
else
{
long double angA=2*acos( (K(a.r)+K(dis)-K(b.r))/(2*a.r*dis) );
long double angB=2*acos( (K(b.r)+K(dis)-K(a.r))/(2*b.r*dis) );
long double areaA=K(a.r)*(angA-sin(angA))/2;
long double areaB=K(b.r)*(angB-sin(angB))/2;
return areaA+areaB;
}
}
}a,b;
int main()
{
while(cin>>a.x>>a.y>>a.r>>b.x>>b.y>>b.r)
{
cout<<setprecision(25)<<a.Intersection_area(a,b);
}
return 0;
}
/*
~两圆关系模板,wkc倾力打造~
类型:两圆之间的关系可能是相离,外切,相交,内切,内含这五种。它们都可以利用圆心距离与半径之间的关系来确定。
设两圆圆心距为dis,两圆半径分别是r0和r1,那么,我们有——
if(dis>r0+r1)then 两圆相离
if(dis==r0+r1)then 两圆外切
if(dis==fabs(r0-r1))then 两圆内切
if(dis<fabs(r0-r1))then 两圆内含
if(dis>fabs(r0-r1)&&dis<r0+r1)then 两圆相切
相离,外切:相交面积为0
内切,内含:相交面积为小圆面积
相交:相交面积可以用扇形面积减去三角形面积求得
特别说明:long double要用cin cout输入输出。用iomanip库中的setprecision(15)输出精度,最高15位。
*/【Educational Codeforces Round 2D】【计算几何 圆面积交 模板】Area of Two Circles' Intersection
最新推荐文章于 2018-12-07 13:36:00 发布
本文介绍了一种计算两个圆交集面积的方法,并提供了一个C++实现示例。该算法适用于不同位置和大小的圆,包括相离、外切、相交、内切和内含等情形。


1449

被折叠的 条评论
为什么被折叠?



