Circular Area

本文介绍了一种计算两个圆交叠部分面积的方法,并提供了一个使用C语言实现的具体示例程序。该程序能够准确地计算出两个圆交叠区域的面积。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

点击打开链接http://poj.org/problem?id=2546

Time Limit: 1000MS

Memory Limit: 65536K

Total Submissions: 1843

Accepted: 808

Description
Your task is to write a program, which, given two circles, calculates the area of their intersection with the accuracy of three digits after decimal point.

Input
In the single line of input file there are space-separated real numbers x1 y1 r1 x2 y2 r2. They represent center coordinates and radii of two circles.

Output
The output file must contain single real number - the area.

Sample Input

20.0 30.0 15.0 40.0 30.0 30.0

Sample Output

608.366

Source
Northeastern Europe 2000, Far-Eastern Subregion

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

求两圆的公共面积:
#include<stdio.h>

#include<math.h>

#define pi acos(-1)

int main()

{

    double x1,y1,a,x2,y2,b,c,A,B,ans,p,s,s1,s2;

    scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&a,&x2,&y2,&b);

    c=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));

    if(a<b)

    {

        double t=a;

        a=b;

        b=t;

    }

    if(c>=a+b)

      {

       printf("0.000\n");

       return 0;

      }

    if(c<=a-b)

    {

        ans=pi*b*b;

        printf("%.3lf\n",ans); return 0;

    }

    A=acos((a*a+c*c-b*b)/(2.0*a*c));

    B=acos((b*b+c*c-a*a)/(2.0*b*c));

    p=(a+b+c)/2.0;

    s=sqrt(p*(p-a)*(p-b)*(p-c));

    A=acos((b*b+c*c-a*a)/2/b/c);

    B=acos((a*a+c*c-b*b)/2/a/c);

    s=sqrt(p*(p-a)*(p-b)*(p-c));

    ans=a*a*B+b*b*A-2*s;

    printf("%.3lf\n",ans);

    return 0;

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值