UESTC1713 无关青云路,无关诗书,无你处,无江湖
题意:给出两个圆的坐标求两圆相交的面积
题解:两个圆相交,包含,相离,相切等情况,判断两个圆心的距离与半径的关系,相交的部分可以看作是两个扇形减去菱形的面积
#include <stdio.h> #include <math.h> #define PI acos(-1) double x1,x2,yy,y2,R,r,s1,s2,p,s3,l, s5,s4; int main(){ int T; scanf("%d", &T); while(T--){ scanf("%lf%lf%lf%lf%lf%lf", &x1, &yy, &r, &x2, &y2, &R); l = sqrt((x1-x2)*(x1-x2)+(yy-y2)*(yy-y2)); //cout<<l<<endl; if(R<r) { s5 = R; R = r; r = s5; } if(R >= l+r) printf("%.6f\n", r*r*PI); else if(l >= R+r) printf("%.6f\n", 0); else{ s1 = acos((r*r+l*l-R*R)/2/r/l); s2 = acos((R*R+l*l-r*r)/2/R/l); s3 = cos(s1)*r*sin(s1)*r; s4 = cos(s2)*R*sin(s2)*R; s1 = r*r*s1; s2 = R*R*s2; printf("%f\n", s1-s3+s2-s4); } } return 0; }
posted on 2017-07-23 21:21 2855669158 阅读(298) 评论(0) 编辑 收藏 举报