您的位置:首页 > 其它

【Educational Codeforces Round 2D】【计算几何 圆面积交 模板】Area of Two Circles' Intersection

2015-11-30 09:28 621 查看
D. Area of Two Circles' Intersection

time limit per test
2 seconds

memory limit per test
256 megabytes

input
standard input

output
standard output

You are given two circles. Find the area of their intersection.

Input
The first line contains three integers x1, y1, r1 ( - 109 ≤ x1, y1 ≤ 109, 1 ≤ r1 ≤ 109)
— the position of the center and the radius of the first circle.
The second line contains three integers x2, y2, r2 ( - 109 ≤ x2, y2 ≤ 109, 1 ≤ r2 ≤ 109)
— the position of the center and the radius of the second circle.

Output
Print the area of the intersection of the circles. The answer will be considered correct if the absolute or relative error doesn't exceed10 - 6.

Sample test(s)

input
0 0 4
6 0 4


output
7.25298806364175601379


input
0 0 5
11 0 5


output
0.00000000000000000000


#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位。

*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息