zoj 1597 Circular Area (求两园相交面积)

# include <algorithm>
# include <stdio.h>
# include <string.h>
# include <iostream>
# include <math.h>
using namespace std;
# define PI acos(-1.0)
const double eps = 1e-8;
struct  node
{
    double x;
    double y;
    double r;
};
struct node a1[10];

double dis(double x1,double y1,double x2,double y2)
{
    return sqrt( (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2) );
}
double area()///不相离不相含求相交面积
{
    double a = dis(a1[1].x,a1[1].y,a1[0].x,a1[0].y), b = a1[0].r, c = a1[1].r;
    double cta1 = acos((a * a + b * b - c * c) / 2 / (a * b)),
           cta2 = acos((a * a + c * c - b * b) / 2 / (a * c));
    double s1 = a1[0].r*a1[0].r*cta1 - a1[0].r*a1[0].r*sin(cta1)*(a * a + b * b - c * c) / 2 / (a * b);
    double s2 = a1[1].r*a1[1].r*cta2 - a1[1].r*a1[1].r*sin(cta2)*(a * a + c * c - b * b) / 2 / (a * c);
    return s1 + s2;
}
int main()
{
    double x1,x2,y1,y2,xx1,xx2,yy1,yy2;
    double d1,d2,d3,d4,d5,d6,d7,d8;
    while(~scanf("%lf %lf %lf %lf %lf %lf",&a1[0].x,&a1[0].y,&a1[0].r,&a1[1].x,&a1[1].y,&a1[1].r))
    {
        if(dis(a1[0].x,a1[0].y,a1[1].x,a1[1].y)<=fabs(a1[0].r-a1[1].r))///相包含
        {
            if(a1[1].r>a1[0].r)
                  printf("%.3lf\n",PI*a1[0].r*a1[0].r);
            else
                printf("%.3lf\n",PI*a1[1].r*a1[1].r);
        }
        else if(dis(a1[0].x,a1[0].y,a1[1].x,a1[1].y)>=a1[0].r+a1[1].r)///相离
            printf("0.000\n");
        else ///相交
        printf("%.3lf\n",area());
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值