Tell me the area
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3183 Accepted Submission(s): 1034
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>
int main()
{
double q,w,m,n,a,b,c,x,y,z,PI;
PI=2*asin(1.0);
while(~scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&x,&y,&z))
{
a=sqrt((a-x)*(a-x)+(b-y)*(b-y));
if(a>=c+z||!c||!z)x=0;
else if(a<=fabs(z-c))
{
if(z>c)z=c;
x=z*z*PI;
}
else{
b=acos((a*a+c*c-z*z)/(2*a*c));
y=acos((a*a+z*z-c*c)/(2*a*z));
m=b*c*c;
n=y*z*z;
q=c*c*sin(b)*cos(b);
w=z*z*sin(y)*cos(y);
x=m+n-(q+w);
}
printf("%.3f\n",x);
}
return 0;
}