求两圆相交的面积

走自己的路,你会发现,在走的过程中你会收获很多

#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <limits.h>
#include <ctype.h>
#include <string.h>
#include <string>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <deque>
#include <vector>
#include <set>
#include <map>
using namespace std;

double dis(int x1,int y1,int x2,int y2){
    double len = sqrt((x1-x2+0.0)*(x1-x2+0.0)+(y1-y2+0.0)*(y1-y2+0.0));
    return len;
}

double f(int x1,int y1,int r1,int x2,int y2,int r2){
    double a = dis(x1,y1,x2,y2), b = r1+0.0, c = r2+0.0;
	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 = (r1+0.0)*r1*cta1 - (r1+0.0)*r1*sin(cta1)*(a * a + b * b - c * c) / 2 / (a * b);
	double s2 = (r2+0.0)*r2*cta2 - (r2+0.0)*r2*sin(cta2)*(a * a + c * c - b * b) / 2 / (a * c);
	return s1 + s2;
}

int main(){
    int x1,y1,x2,y2,r1,r2;

    while(~scanf("%d%d%d%d%d%d",&x1,&y1,&r1,&x2,&y2,&r2)){
        double ans = f(x1,y1,r1,x2,y2,r2);
        printf("%.4lf\n",ans);
    }

    return 0;
}
时间: 2024-10-06 17:57:11

求两圆相交的面积的相关文章

POJ 2546 &amp; ZOJ 1597 Circular Area(求两圆相交的面积 模板)

题目链接: POJ:http://poj.org/problem?id=2546 ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=597 Description Your task is to write a program, which, given two circles, calculates the area of their intersection with the accuracy of three di

求两圆相交部分面积(C++)

已知两圆圆心坐标和半径,求相交部分面积: 1 #include <iostream> 2 using namespace std; 3 #include<cmath> 4 #include<stdio.h> 5 #define PI 3.141593 6 struct point//点 7 { 8 double x,y; 9 }; 10 struct circle//圆 11 { 12 point center; 13 double r; 14 }; 15 float

hdu 5120 (求两圆相交的面积

题意:告诉你两个圆环,求圆环相交的面积. /* gyt Live up to every day */ #include<cstdio> #include<cmath> #include<iostream> #include<algorithm> #include<vector> #include<stack> #include<cstring> #include<queue> #include<set&

hdu 5120 (求两圆相交的面积的公式)

S = A大B大 - A大B小 - A小B大 + A小B小.(A表示A环,大表示大圆,B同).然后直接套模板,,,, 1 #include <stdio.h> 2 #include <algorithm> 3 #include <string.h> 4 #include <cmath> 5 using namespace std; 6 7 const double eps = 1e-8; 8 const double PI = acos(-1.0); 9 1

hdu 3264 Open-air shopping malls 求两圆相交

对每个圆二分半径寻找可行的最小半径,然后取最小的一个半径. 对于两圆相交就只要求到两个扇形,然后减去两个全等三角形就行了. #include<cstdio> #include<iostream> #include<cmath> #include<algorithm> using namespace std; #define pi acos(-1.0) #define eps 1e-8 #define maxn 50 int n; struct point{

求两圆相交面积模板

#define PI 3.141592654 #define eps 1e-8 double getdis(int x1,int y1,int x2,int y2){ return sqrt((double)(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)); } double getarea(int x1,int y1,double r1,int x2,int y2,double r2){ double d=getdis(x1,y1,x2,y2); if(r1+r2<d+eps)

HDU 1798 两圆相交面积

Tell me the area Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1755    Accepted Submission(s): 535 Problem Description There are two circles in the plane (shown in the below picture), there is

poj 2546 Circular Area (两圆相交面积)

链接:poj 2546 题意:已知两圆的圆心和半径,求两圆相交部分的面积 分析:两圆的位置关系有三种:相离,相交,内含 相离时:相交面积为0 相交时,大扇形面积+小扇形面积-四边形面积 内含时,相交面积为小圆面积 #include<stdio.h> #include<math.h> #define PI acos(-1.0) typedef struct stu { double x,y; }point; double Distance(point a,point b) { ret

POJ 2546 Circular Area(两个圆相交的面积)

题目链接 题意 : 给你两个圆的半径和圆心,让你求两个圆相交的面积大小. 思路 : 分三种情况讨论 假设半径小的圆为c1,半径大的圆为c2. c1的半径r1,圆心坐标(x1,y1).c2的半径r2,圆心坐标(x2,y2). d为两圆圆心连线的长度. 相交面积为S d=sqrt((x1-x2)^2+(y1-y2)^2) (1)如果r1+r2<=d 那么两圆相离,相交面积S=0 (2)如果r2-r1>=d 那么半径小的圆内含半径大的圆,那么相交面积为小圆的面积S=pi*r1*r1 (3)既非(1)