题意:
给两个圆,求它们的面积交。
分析:
海伦公式,余弦定理等可解。
代码:
//poj 2546 //sep9 #include <iostream> #include <cmath> using namespace std; const double pi=acos(-1.0); int main() { double x1,y1,r1,x2,y2,r2; scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&r1,&x2,&y2,&r2); double d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); if(d>=r1+r2){ printf("%.3lf",0); return 0; } if(d<=max(r1,r2)-min(r1,r2)){ printf("%.3lf",pi*min(r1,r2)*min(r1,r2)); return 0; } double p=(r1+r2+d)/2; double s=2*sqrt(p*(p-r1)*(p-r2)*(p-d)); double A1=2*acos((r1*r1+d*d-r2*r2)/(2*r1*d)); double A2=2*acos((r2*r2+d*d-r1*r1)/(2*r2*d)); double s1=A1*r1*r1/2; double s2=A2*r2*r2/2; printf("%.3lf",s1+s2-s+1e-9); return 0; }
原文地址:http://blog.csdn.net/sepnine/article/details/43051645