俩个圆的重合面积

Tell me the area

 

Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)

Total Submission(s) : 4   Accepted Submission(s) : 0

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

#include<stdio.h>
#include<math.h>
#define PI acos(-1.0)
int main()
{
    double a1,b1,r1,a2,b2,r2,d;
    double A1,A2,s1,s2,s;
    while(scanf("%lf%lf%lf%lf%lf%lf",&a1,&b1,&r1,&a2,&b2,&r2)!=EOF)
    {
        d=sqrt((a2-a1)*(a2-a1)+(b2-b1)*(b2-b1));
        if(d>=r1+r2)    printf("0.000\n");
        else if(d<=fabs(r1-r2)&&d>=0)
        {
            if(r1>r2)
                    printf("%0.3lf\n",PI*r2*r2);
            else printf("%0.3lf\n",PI*r1*r1);
        }
        else {
            A1=2*acos((d*d+r1*r1-r2*r2)/(2*d*r1));
            A2=2*acos((d*d+r2*r2-r1*r1)/(2*d*r2));
            //cos(A1)=(d*d+r1*r1-r2*r2)/(2*d*r1);
            //cos(A2)=(d*d+r1*r1-r2*r2)/(2*d*r1);
            s1=0.5*r1*r1*sin(A1)+0.5*r2*r2*sin(A2);
            s2=(A1)/2*r1*r1+(A2)/2*r2*r2;
            s=s2-s1;
            printf("%.03lf\n",s);
        }
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据引用\[1\]和引用\[3\]提供的信息,可以使用MATLAB的蒙特卡罗方法来计算两个重合部分面积。蒙特卡罗方法是一种基于随机抽样的数值计算方法,通过生成大量的随机点,并统计落在重合部分内的点的比例来估计面积。 首先,需要掌握MATLAB绘制椭的基本知识,可以参考引用\[2\]中提供的链接。根据椭的中心坐标、长半轴、偏心率和方向角,可以使用MATLAB绘制出两个。 然后,可以使用蒙特卡罗方法来估计两个重合部分面积。具体步骤如下: 1. 在两个的外接矩形内生成大量的随机点。 2. 对于每个随机点,判断其是否在两个的内部。 3. 统计落在两个内部的点的数量。 4. 计算重合部分面积的估计值,即落在两个内部的点的数量除以总点数,并乘以外接矩形的面积。 需要注意的是,蒙特卡罗方法是一种近似计算方法,估计的结果可能会有一定的误差。为了提高计算结果的准确性,可以增加生成的随机点的数量。 希望以上信息对您有所帮助! #### 引用[.reference_title] - *1* *2* *3* [MATLAB 两椭重合面积的填充与计算](https://blog.csdn.net/qq_34122861/article/details/121429870)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值