You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
912 B
C++

#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const double pi=acos(-1),eps=1e-8;
struct
{
int x,y;
} p1,p2;
double intsec(double r1,double r2)
{
double dist=sqrt(pow(p2.x-p1.x,2)+pow(p2.y-p1.y,2));
if(r1+r2<=dist+eps)
return 0;
if(abs(r2-r1)>=dist-eps)
return pi*pow(min(r2,r1),2);
double a1 = acos((r1*r1 + dist*dist - r2*r2) / (2.0*r1*dist));
double a2 = acos((r2*r2 + dist*dist - r1*r1) / (2.0*r2*dist));
return a1*r1*r1 + a2*r2*r2 - r1*dist*sin(a1);
}
int main()
{
int T;
scanf("%d", &T);
for(int t=1; t<=T; t++)
{
double r1,r2;
scanf("%lf%lf", &r1, &r2);
scanf("%d%d", &p1.x, &p1.y);
scanf("%d%d", &p2.x, &p2.y);
double ans = intsec(r2, r2)+intsec(r1, r1) - intsec(r1, r2)*2;
printf("Case #%d: %.6f\n",t, ans);
}
return 0;
}