POJ 2546 Circular Area 两圆相交面积

题目:http://poj.org/problem?id=2546

题意:给定两个圆的圆心和半径,求两个圆的相交面积

思路:满满的高中几何知识,不多说

#include 
#include 
#include 
#include 
#include 
using namespace std;

const double PI = acos(-1.0);
const double eps = 1e-9;
int main()
{
    double x1, y1, r1, x2, y2, r2;
    while(~ scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &r1, &x2, &y2, &r2))
    {
        
        double len = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); //圆心距
        if(len >= r1 + r2) //两圆相离
        {
            printf("0.000\n");
            continue;
        }
        else if(len <= fabs(r1 - r2)) //一圆被另一圆包含
        {
            double r = min(r1, r2);
            printf("%.3f\n", r * r * PI);
        }
        else //两圆相交
        {
            double j1 = acos((len * len + r1 * r1 - r2 * r2) / 2 / len / r1); //从圆心到两焦点连线所形成的圆心角度数一半
            double j2 = acos((len * len + r2 * r2 - r1 * r1) / 2 / len / r2);
            double hu1 = j1 * r1 * r1; //圆心角对应扇形的面积
            double hu2 = j2 * r2 * r2;
            double s = r1 * len * sin(j1); //两圆心与交点连线构成的四边形面积
            printf("%.3f\n", hu1 + hu2 - s);
        }
    }
    return 0;
}




你可能感兴趣的:(计算几何)