Tell me the area

Tell me the area

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1381    Accepted Submission(s): 430


Problem Description
    There are two circles in the plane (shown in the below picture), there is a common area between the two circles. The problem is easy that you just tell me the common area.

 

Input
There are many cases. In each case, there are two lines. Each line has three numbers: the coordinates (X and Y) of the centre of a circle, and the radius of the circle.
 

Output
For each case, you just print the common area which is rounded to three digits after the decimal point. For more details, just look at the sample.
 

Sample Input
  
  
0 0 2 2 2 1
 

Sample Output
  
  
0.108
 

Author
wangye
 

Source
 

Recommend
wangye
#include<stdio.h>
#include<math.h>
int main()
{
    double q,w,m,n,a,b,c,x,y,z,PI;
    PI=2*asin(1.0);
    while(~scanf("%lf%lf%lf",&a,&b,&c)){
        scanf("%lf%lf%lf",&x,&y,&z);
        a=sqrt((a-x)*(a-x)+(b-y)*(b-y));//计算圆心距
        //如果两圆相离、外切或至少一圆半径为0时,那么所求面积为0
        if(a>=c+z||!c||!z)x=0;
        //如果两内切或内含,那么所求面积为小圆面积
        else if(a<=fabs(z-c)){
            if(z>c)z=c;
            x=z*z*PI;
        }
        //如果两圆相交,面积求解如下
        else{
            //由余弦定理求出公共弦在圆o1中对应的圆心角的一半
            b=acos((a*a+c*c-z*z)/(2*a*c));
            //由余弦定理求出公共弦在圆o2中对应的圆心角的一半
            y=acos((a*a+z*z-c*c)/(2*a*z));
            //计算圆o1中扇形面积
            m=b*c*c;
            //计算圆o2中扇形面积
            n=y*z*z;
            //计算圆o1中扇形所对应的三角形面积
            q=c*c*sin(b)*cos(b);
            //计算圆o2中扇形所对应的三角形面积
            w=z*z*sin(y)*cos(y);
            //q+w为图中四边形面积,两扇形面积之和与四边形面积之差即为
            //所求面积。在图2中y为钝角,计算出的面积w为负值,这时q+w
            //表示两三角面积之差,刚好还是四边形面积,因此对于图1和图
            //2不必分情况讨论
            x=m+n-(q+w);
        }
        printf("%.3f\n",x);
    }
    return 0;
}

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值