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

来源:互联网 发布:dreamweaver有mac版吗 编辑:程序博客网 时间:2024/04/29 07:18

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 22 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.1415926using 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