Tell me the area(计算几何--求两圆相交面积)


Problem Link:http://acm.hdu.edu.cn/showproblem.php?pid=1798


Tell me the area

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


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


AC code:

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#define PI acos(-1)

using namespace std;

int main()
{
	int T;
	double r1,r2,x1,x2,y1,y2,dr,r,A1,A2,p,s,s1,s2,ans;	
	while(scanf("%lf%lf%lf",&x1,&y1,&r1)!=EOF)
	{
		scanf("%lf%lf%lf",&x2,&y2,&r2);
		dr=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
		r=min(r1,r2);
		if(dr>=r1+r2)
			printf("0.000\n");
		else if(dr<=fabs(r1-r2) && dr>=0)
		{
			ans=PI*r*r;
			printf("%0.3lf\n",ans);
		}
		else
		{
			A1=acos((r1*r1+dr*dr-r2*r2)/(2*r1*dr));
			A2=acos((r2*r2+dr*dr-r1*r1)/(2*r2*dr));
			p=(r1+r2+dr)/2;
			s=sqrt(p*(p-r1)*(p-r2)*(p-dr));
			s1=s-PI*r2*r2*(A2/(2*PI));
			s2=s-PI*r1*r1*(A1/(2*PI));
			ans=2*(s-s1-s2);
			printf("%.3lf\n",ans);
		}		
	}
	return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

林下的码路

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值