Circular Area 两圆相交面积(模板)

Circular Area
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 5272 Accepted: 2100

Description

Your task is to write a program, which, given two circles, calculates the area of their intersection with the accuracy of three digits after decimal point.

Input

In the single line of input file there are space-separated real numbers x1 y1 r1 x2 y2 r2. They represent center coordinates and radii of two circles.

Output

The output file must contain single real number - the area.

Sample Input

20.0 30.0 15.0 40.0 30.0 30.0

Sample Output

608.366

套模板求解两圆相交的面积

code:

<span style="font-size:18px;">#include<iostream>
#include<stdio.h>
#include<cmath>
#include<cstring>
using namespace std;
const double pi = 3.141592653;
int flag;
double solve( double r, double r0, double dis )
{
  double ang = 2*acos( (r*r + dis*dis - r0*r0) / (2*r*dis ) );//公式
  double s2  = 0.5*r*r*sin(ang);
  double s1  = 0.5*r*r*ang;
  return s1 - s2;
}
int main( )
{

  double x,y,r,x0,y0,r0,dis,ans;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
  while( scanf( "%lf%lf%lf%lf%lf%lf",&x,&y,&r,&x0,&y0,&r0 ) != EOF )
  {
    flag=0;
    dis = sqrt( ( x - x0 )*( x - x0 ) + ( y - y0 )*( y - y0 ) );
    if( r < r0 )
    swap(r,r0);
    if(dis>=(r+r0))
        printf("0.000\n");
    else if(dis+r0<=r)
        printf("%.3lf\n",pi*r0*r0);
    else
        printf("%.3lf\n",solve(r,r0,dis)+solve(r0,r,dis));
  }
  return 0;
}</span>



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值