两圆相交求面积 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 ...
随机推荐
- 《Python游戏编程快速上手》——1.3 如何使用本书
本节书摘来自异步社区<Python游戏编程快速上手>一书中的第1章,第1.3节,作者[美] Al Sweigart(斯维加特),李强 译,更多章节内容可以访问云栖社区"异步社区& ...
- 团队一致性的PHP开发环境之Docker
docker php环境模型 docker 简介 Docker 是一个开源的应用容器引擎 让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现 ...
- 修复.NET的HttpClient
\ 看新闻很累?看技术新闻更累?试试下载InfoQ手机客户端,每天上下班路上听新闻,有趣还有料! \ \\ 早在2016年我们就报道过 ,.NET的HttpClient存在一些问题.随着.NET Co ...
- 使用BottomNavigationView+ViewPager+Fragment的底部导航栏
2019独角兽企业重金招聘Python工程师标准>>> 使用BottomNavigationView做底部工具栏,使用ViewPager做页面切换,使用Fragment完成每个页面的 ...
- 求x>0时,y=x^3-6x^2+15的极值
解: 当x→∞时,y也→∞,所以y没有最大值. y=x3-6x2+15=-4*(x/2)*(x/2)*(6-x)+15 而根据几何平均数小于等于算术平均数的定理,(x/2)*(x/2)*(6-x)在x ...
- 【原创】Linux Mutex机制分析
背景 Read the fucking source code! --By 鲁迅 A picture is worth a thousand words. --By 高尔基 说明: Kernel版本: ...
- MAC使用Scrapy遇到的坑
MAC版本:EI Captain Python版本: 2.7.10 MAC默认没有安装pip,所以首先 sudo easy_install pip 然后安装Scrapy: sudo pip insta ...
- Java——集合系列(1)框架概述
该系列博文会告诉你如何从入门到进阶,一步步地学习Java基础知识,并上手进行实战,接着了解每个Java知识点背后的实现原理,更完整地了解整个Java技术体系,形成自己的知识框架. 集合框架概述 Jav ...
- (Lineup the Dominoes筛子)三维状压
传送门 描述:\(一堆筛子,每个筛子两个面,上面有1-6之间的数字.后一个筛子与前一个筛子的接触面的点数必须相等.\) \(求,有多少种方案堆完筛子.(方案只关心筛子的位置,不关心是否翻转)\) \( ...
- 安装MySQL8(附详细图文)
安装MySQL8(附详细图文) 删除mysql服务:mysqld -remove mysql 1.下载 mysql 8 下载地址:https://dev.mysql.com/downloads/mys ...