两圆相交求面积 hdu5120
两圆相交分如下集中情况:相离、相切、相交、包含。
设两圆圆心分别是O1和O2,半径分别是r1和r2,设d为两圆心距离。又因为两圆有大有小,我们设较小的圆是O1。
相离相切的面积为零,代码如下:
- double d = sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
- if (d >= r1+r2)
- return 0;
double d = sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
if (d >= r1+r2)
return 0;
包含的面积就是小圆的面积了,代码如下:
- if(r2 - r1 >= d)
- return pi*r1*r1;
if(r2 - r1 >= d)
return pi*r1*r1;
接下来看看相交的情况。
相交面积可以这样算:扇形O1AB - △O1AB + 扇形O2AB - △O2AB,这两个三角形组成了一个四边形,可以用两倍的△O1AO2求得,
所以答案就是两个扇形-两倍的△O1AO2
因为
所以
那么
同理
接下来是四边形面积:
代码如下:
double ang1=acos((r1*r1+d*d-r2*r2)/(*r1*d));
double ang2=acos((r2*r2+d*d-r1*r1)/(*r2*d));
return ang1*r1*r1 + ang2*r2*r2 - r1*d*sin(ang1);
#include<iostream>
#include<cmath>
using namespace std; #define pi acos(-1.0) typedef struct node
{
int x;
int y;
}point; double AREA(point a, double r1, point b, double r2)
{
double d = sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
if (d >= r1+r2)
return ;
if (r1>r2)
{
double tmp = r1;
r1 = r2;
r2 = tmp;
}
if(r2 - r1 >= d)
return pi*r1*r1;
double ang1=acos((r1*r1+d*d-r2*r2)/(*r1*d));
double ang2=acos((r2*r2+d*d-r1*r1)/(*r2*d));
return ang1*r1*r1 + ang2*r2*r2 - r1*d*sin(ang1);
} int main()
{
point a, b;
a.x=, a.y=;
b.x=, b.y=;
double result = AREA(a, , b, );
printf("%lf\n", result);
return ;
}
Intersection
Time Limit: 4000/4000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)
Total Submission(s): 3443 Accepted Submission(s): 1302
A ring is a 2-D figure bounded by two circles sharing the common center. The radius for these circles are denoted by r and R (r < R). For more details, refer to the gray part in the illustration below.
Matt just designed a new logo consisting of two rings with the same size in the 2-D plane. For his interests, Matt would like to know the area of the intersection of these two rings.
Each of the following two lines contains two integers xi, yi (0 ≤ xi, yi ≤ 20) indicating the coordinates of the center of each ring.
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
double x1,ya,x2,y2,dis,s1,s2,s3,R,r;
double sov(double R,double r){
if(dis>=r+R) return ;
if(dis<=R-r) return acos(-1.0)*r*r;
double x=(R*R-r*r+dis*dis)/2.0/dis;
double y=(r*r-R*R+dis*dis)/2.0/dis;
double seta1=*acos(x/R);
double seta2=*acos(y/r);
double ans=seta1*R*R/2.0+seta2*r*r/2.0;
double h=sqrt(R*R-x*x);
return ans-dis*h;
}
int main(){
int tas=,T;
for(scanf("%d",&T);T--;){
scanf("%lf%lf",&r,&R);
scanf("%lf%lf%lf%lf",&x1,&ya,&x2,&y2);
dis=sqrt((x1-x2)*(x1-x2)+(ya-y2)*(ya-y2));
s1=sov(R,R),s2=sov(R,r),s3=sov(r,r);
printf("Case #%d: %.6f\n",tas++,s1-*s2+s3);
}
}
两圆相交求面积 hdu5120的更多相关文章
- POJ 2546 & ZOJ 1597 Circular Area(求两圆相交的面积 模板)
题目链接: POJ:http://poj.org/problem? id=2546 ZOJ:problemId=597" target="_blank">http: ...
- hdu 5120 (求两圆相交的面积
题意:告诉你两个圆环,求圆环相交的面积. /* gyt Live up to every day */ #include<cstdio> #include<cmath> #in ...
- 求两圆相交部分面积(C++)
已知两圆圆心坐标和半径,求相交部分面积: #include <iostream> using namespace std; #include<cmath> #include&l ...
- POJ 2546 Circular Area(两个圆相交的面积)
题目链接 题意 : 给你两个圆的半径和圆心,让你求两个圆相交的面积大小. 思路 : 分三种情况讨论 假设半径小的圆为c1,半径大的圆为c2. c1的半径r1,圆心坐标(x1,y1).c2的半径r2,圆 ...
- poj2546Circular Area(两圆相交面积)
链接 画图推公式 这两种情况 都可用一种公式算出来 就是两圆都求出圆心角 求出扇形的面积减掉三角形面积 #include <iostream> using namespace std; # ...
- hdu5858 Hard problem(求两圆相交面积)
题目传送门 Hard problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- LightOJ 1118--Incredible Molecules(两圆相交)
1118 - Incredible Molecules PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Lim ...
- 西南民大oj(两园交求面积)
西南民大oj:http://www.swunacm.com/acmhome/welcome.do?method=index 我的几何不可能那么可爱 时间限制(普通/Java) : 1000 MS/ 3 ...
- 牛客网暑期ACM多校训练营(第三场)J 多边形与圆相交的面积
链接:https://www.nowcoder.com/acm/contest/141/J 题目描述 Eddy has graduated from college. Currently, he is ...
随机推荐
- 标准库shelve
shelve模块是一个简单的k,v将内存数据通过文件持久化的模块,可以持久化任何pickle可支持的python数据格式. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ...
- 标准库os
os模块 提供对操作系统进行调用的接口 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 os ...
- SQLCommand 相关应用
SQL command 对象:执行指定数据库中相应的操作 (执行相应的SQL语句)string str1 = "select * from tb_student "Create: ...
- 【10月新版】Aspose.Pdf 10月新版V17.10发布 | 附下载
2019独角兽企业重金招聘Python工程师标准>>> Aspose.Pdf for .NET 17.10 更新 功能和改进 核心 概述 类别 PDFNET-38067 支持DICO ...
- 贪心--HDU 2021 发工资咯
Description 作为杭电的老师,最盼望的日子就是每月的8号了,因为这一天是发工资的日子,养家糊口就靠它了,呵呵,但是对于学校财务处的工作人员来说,这一天则是很忙碌的一天,财务处的小胡老师最近就 ...
- 数学--数论--Hdu 1452 Happy 2004(积性函数性质+和函数公式+快速模幂+乘法逆元)
Consider a positive integer X,and let S be the sum of all positive integer divisors of 2004^X. Your ...
- JAVA大数--POJ 1715 大菲波数
Problem Description Fibonacci数列,定义如下: f(1)=f(2)=1 f(n)=f(n-1)+f(n-2) n>=3. 计算第n项Fibonacci数值. Inp ...
- 从垃圾回收机制解析为什么局部内部类只能访问final修饰的局部变量以及为什么加final能解决问题
我们先稍微看一下代码: 从这里的提示可以看到,必须要将a的修饰符变为final才行. 现在笔者就这一结果做出自己的分析: 首先来说,我们知道,方法被调用时会执行,当执行的时候,方法中的局部变量会加载到 ...
- GroupJoin()各参数的意义及用法
EF Core中GroupJoin的注释比较复杂: public static IEnumerable<TResult> GroupJoin<TOuter, TInner, TKey ...
- [hdu5534]DP
题目原意:给一棵n个点的树添加边,给定度函数f(d)为一个点的度的函数,求所有点的度函数的和 思路: 函数只与点的度有关,而与点无关,n个点的树有n-1条边,共产生2(n-1)个度,每个点至少有1个度 ...