poj2546
两个圆的面积并(也就是面积交)
总之算出相交的四边形的面积。。然后就可以了。。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;
const int MAXN = 1e3 + 5;
const double EPS = 1e-6;
double PI;
struct Point
{
Point() {}
Point(double _x, double _y): x(_x), y(_y) {}
double getDis(Point rhs)
{
double xx = rhs.x - x, yy = rhs.y - y;
return sqrt(xx * xx + yy * yy);
}
double x, y;
};
double operator ^(Point lhs, Point rhs){return lhs.x * rhs.y - lhs.y * rhs.x;}
Point operator -(Point lhs, Point rhs){return Point(lhs.x - rhs.x, lhs.y - rhs.y);}
Point operator /(Point lhs, double rhs){return Point(lhs.x / rhs, lhs.y / rhs);}
Point operator *(Point lhs, double rhs){return Point(lhs.x * rhs, lhs.y * rhs);}
struct Circle
{
Circle() {}
Circle(Point _o, double _r): o(_o), r(_r) {}
double getDis(Circle &rhs)
{
return o.getDis(rhs.o);
}
double getArea()
{
return PI * r * r;
}
Point o;
double r;
bool operator <(const Circle &rhs) const
{
return o.x < rhs.o.x;
}
};
Circle a, b;
Point rotate(Point &t, double cosd, double sind)
{
return Point(t.x * cosd -t.y * sind, t.x * sind + t.y * cosd);
}
int main()
{
PI = acos(-1.0);
double ans = 0.0;
scanf("%lf%lf%lf%lf%lf%lf", &a.o.x, &a.o.y, &a.r, &b.o.x, &b.o.y, &b.r);
double dis = a.getDis(b);
if(dis >= a.r + b.r)
{
ans = 0.0;
}
else if(dis <= fabs(a.r - b.r))
{
if(a.r > b.r) ans = b.getArea();
else ans = a.getArea();
}
else
{
double cosd = (a.r * a.r + dis * dis - b.r * b.r) / (2.0 * a.r * dis);
double cosd2 = (b.r * b.r + dis * dis - a.r * a.r) / (2.0 * b.r * dis);
double degree = acos(cosd) * 2;
double degree2 = acos(cosd2) * 2;
double sind = sin(degree), sind2 = sin(degree2);
double s1, s2;
s1 = degree * a.r * a.r / 2.0;
s2 = degree2 * b.r * b.r / 2.0;
ans = s1 + s2 - a.r * a.r * sind / 2 - b.r * b.r * sind2 / 2;
}
printf("%.3lf\n", ans);
}