HDU1798 简单高中的计算几何题= =。正余弦定理的综合应用么。。。

Tell me the area

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


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 题意:给你两圆坐标和各自的半径,求公共部分面积。 思路:分析两圆关系先:1.外切或相离面积为0 2.内含或内切面积为小圆面积。 3.相交:A.相交弦在圆心之间 B.相交弦在圆心一侧:后面发现算面积的时候不会有影响。 4.一开始没注意的:两圆可能半径为0.....略坑。。。 相交做法:S=S扇形1+S扇形2-S三角形1-S三角形2,具体可以自己画图。。。高中应该做过类似的解析几何题。。。 注意:后面还WA了一次是因为PI的精度不够,后来换上了官方PI的写法A了- -|||。。。 上代码。。。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
//#define PI 3.1415926
using namespace std;

int main()
{

    double x1,y1,r1;
    double x2,y2,r2;
    double dis;
    double s;
    double a1,a2;
    double s1,s2,ss1,ss2;
    double PI=2*asin(1.0);
    //printf("%.10lf\n",PI);

    while(cin>>x1>>y1>>r1)
    {
        cin>>x2>>y2>>r2;
        dis=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
        if(dis>=r1+r2||r1==0||r2==0)//两圆外切或相离或有圆的半径为0
            s=0;
        else
            if(dis<=abs(r1-r2))//两圆内含或者内切
        {
            if(r1>r2)
                r1=r2;
            s=PI*r1*r1;
        }
        else
        {
            a1=acos((dis*dis+r1*r1-r2*r2)/(2*dis*r1));//在圆O1内的圆心角一半
            a2=acos((dis*dis+r2*r2-r1*r1)/(2*dis*r2));//在圆O2内的圆心角一半
            s1=r1*r1*sin(a1)*cos(a1);//正弦定理(r1*r1*sin2a2)/2的化简
            s2=r2*r2*sin(a2)*cos(a2);//同上
            ss1=r1*r1*a1;//第一个扇形的面积。
            ss2=r2*r2*a2;//第二个扇形的面积
            s=ss1+ss2-s1-s2;//两个扇形的面积之和减去两个三角形的面积。

        }

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

    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值