计算两圆相交 的面积。
参考文章:http://blog.sina.com.cn/s/blog_850498e20100w6fq.html
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
#define INF 0x3fffffff
#define MAXN 100001
#define pi acos(-1.0)
#define eps 10e-7
double calS(double r1,double x1,double y1,double r2,double x2,double y2){
double a1,a2, d;
d = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
if(r2-r1>= d){
return pi*r1*r1;
}
if(r1+r2 <d)return 0;
a1 = acos((r1*r1 + d*d - r2*r2)/(2.0*r1*d));
a2 = acos((r2*r2 + d*d - r1*r1)/(2.0*r2*d));
return a1*r1*r1 + a2*r2*r2 - r1*d*sin(a1);
}
int main()
{
double x1,x2,y1,y2,r1,r2, dist,ans;
while(~scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&r1,&x2,&y2,&r2)){
if(r1 > r2){printf("%.3f\n",calS(r2,x2,y2,r1,x1,y1));}
else printf("%.3f\n",calS(r1,x1,y1,r2,x2,y2));
}
return 0;
}
标签:hdu,r1,r2,Area,double,x2,y1,y2,Circular From: https://blog.51cto.com/u_16192154/6767459