Tell me the area(计算几何--求两圆相交面积)
2018-03-29 19:37
537 查看
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.
![](http://acm.sdibt.edu.cn/vjudge/ojFiles/hdu/data/images/C125_1007_1.jpg)
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 Input0 0 2
2 2 1 Sample Output
0.108
acos()函数调用时括号内是弧度弧度=角度*π/180
#include <stdio.h>
#include<math.h>
#define PI acos(-1.0) //PI就是π
int main()
{
double x1,y1,x2,y2,r1,r2,s,ans,z1,z2,s1,s2,m1,m2;
while(scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&r1,&x2,&y2,&r2)!=EOF)
{
s=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); //求两点之间的距离 if(s>=r1+r2||r1==0||r2==0) //相离的情况
printf("0.000\n");
else if(s<=fabs(r1-r2)&&s>=0) //相切的情况 面积是小圆
{
if(r1<r2)
ans=PI*r1*r1;
else
ans=PI*r2*r2;
printf("%.3lf\n",ans);
}
else //相交的情况
{
z1=acos((r1*r1+s*s-r2*r2)/(2*r1*s)); //这里是余弦定理(对r1 r2 s这个三角形)z1是扇形圆心角一半的弧度
z2=acos((r2*r2+s*s-r1*r1)/(2*r2*s)); //同上
s1=z1*r1*r1; //这里是求扇形的面积 面积公式s=n(圆心角)*π*r*r/360
s2=z2*r2*r2
4000
; //同上
m1=r1*r1*sin(z1)*cos(z1); //这里是求三角形面积 s=1/2*a*b*sin c m2=r2*r2*sin(z2)*cos(z2); //同上
ans=s1+s2-m1-m2;
printf("%.3lf\n",ans);
}
}
return 0;
}
![](http://acm.sdibt.edu.cn/vjudge/ojFiles/hdu/data/images/C125_1007_1.jpg)
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 Input0 0 2
2 2 1 Sample Output
0.108
acos()函数调用时括号内是弧度弧度=角度*π/180
#include <stdio.h>
#include<math.h>
#define PI acos(-1.0) //PI就是π
int main()
{
double x1,y1,x2,y2,r1,r2,s,ans,z1,z2,s1,s2,m1,m2;
while(scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&r1,&x2,&y2,&r2)!=EOF)
{
s=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); //求两点之间的距离 if(s>=r1+r2||r1==0||r2==0) //相离的情况
printf("0.000\n");
else if(s<=fabs(r1-r2)&&s>=0) //相切的情况 面积是小圆
{
if(r1<r2)
ans=PI*r1*r1;
else
ans=PI*r2*r2;
printf("%.3lf\n",ans);
}
else //相交的情况
{
z1=acos((r1*r1+s*s-r2*r2)/(2*r1*s)); //这里是余弦定理(对r1 r2 s这个三角形)z1是扇形圆心角一半的弧度
z2=acos((r2*r2+s*s-r1*r1)/(2*r2*s)); //同上
s1=z1*r1*r1; //这里是求扇形的面积 面积公式s=n(圆心角)*π*r*r/360
s2=z2*r2*r2
4000
; //同上
m1=r1*r1*sin(z1)*cos(z1); //这里是求三角形面积 s=1/2*a*b*sin c m2=r2*r2*sin(z2)*cos(z2); //同上
ans=s1+s2-m1-m2;
printf("%.3lf\n",ans);
}
}
return 0;
}
相关文章推荐
- Tell me the area(计算几何--求两圆相交面积)
- HDU 1798 Tell me the area(计算几何,求相交圆面积)
- hdu 1798 Tell me the area(相交圆的面积)
- hdu---(Tell me the area)(几何/三角形面积以及圆面积的一些知识)
- HDU-1798 Tell me the area (C++和Java【水】两圆相交求公共面积)
- HDU 1798 Tell me the area (计算几何)
- HDU 1798 Tell me the area (两圆相交面积)
- HDU1798 Tell me the area(两圆的相交面积)
- Tell me the area---hdu1798 (数学 几何)
- Hdu 1071 The area 利用计算几何求面积
- Educational Codeforces Round 2D. Area of Two Circles' Intersection(计算几何+圆相交的面积)
- hdoj.2892 area【计算几何+圆与多边形相交面积】 2015/08/17
- Tell me the area 几何
- ACM--两圆交集的面积--HDOJ 1798--Tell me the area
- HDU 1071 The area(计算几何)
- HDU 5858 Hard problem 2016多校10 1002 [相交圆面积]【计算几何】
- HDU 1798 Tell me the area
- poj 1265 Area【计算几何:叉积计算多边形面积+pick定理计算多边形内点数+计算多边形边上点数】
- hdu1798: Tell me the area
- poj1654—Area(计算几何求多边形面积)