转载

两圆相交分如下集中情况:相离、相切、相交、包含。

设两圆圆心分别是O1和O2,半径分别是r1和r2,设d为两圆心距离。又因为两圆有大有小,我们设较小的圆是O1。

相离相切的面积为零,代码如下:

  1. double d = sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
  2. if (d >= r1+r2)
  3. 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;

包含的面积就是小圆的面积了,代码如下:

  1. if(r2 - r1 >= d)
  2. 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

Problem Description
Matt is a big fan of logo design. Recently he falls in love with logo made up by rings. The following figures are some famous examples you may know.


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.

 
Input
The first line contains only one integer T (T ≤ 105), which indicates the number of test cases. For each test case, the first line contains two integers r, R (0 ≤ r < R ≤ 10).

Each of the following two lines contains two integers xi, yi (0 ≤ xi, yi ≤ 20) indicating the coordinates of the center of each ring.

 
Output
For each test case, output a single line “Case #x: y”, where x is the case number (starting from 1) and y is the area of intersection rounded to 6 decimal places.
 
Sample Input
2
2 3
0 0
0 0
2 3
0 0
5 0
 
Sample Output
Case #1: 15.707963
Case #2: 2.250778

#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的更多相关文章

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

    题目链接: POJ:http://poj.org/problem? id=2546 ZOJ:problemId=597" target="_blank">http: ...

  2. hdu 5120 (求两圆相交的面积

    题意:告诉你两个圆环,求圆环相交的面积. /* gyt Live up to every day */ #include<cstdio> #include<cmath> #in ...

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

    已知两圆圆心坐标和半径,求相交部分面积: #include <iostream> using namespace std; #include<cmath> #include&l ...

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

    题目链接 题意 : 给你两个圆的半径和圆心,让你求两个圆相交的面积大小. 思路 : 分三种情况讨论 假设半径小的圆为c1,半径大的圆为c2. c1的半径r1,圆心坐标(x1,y1).c2的半径r2,圆 ...

  5. poj2546Circular Area(两圆相交面积)

    链接 画图推公式 这两种情况 都可用一种公式算出来 就是两圆都求出圆心角 求出扇形的面积减掉三角形面积 #include <iostream> using namespace std; # ...

  6. hdu5858 Hard problem(求两圆相交面积)

    题目传送门 Hard problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  7. LightOJ 1118--Incredible Molecules(两圆相交)

    1118 - Incredible Molecules      PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Lim ...

  8. 西南民大oj(两园交求面积)

    西南民大oj:http://www.swunacm.com/acmhome/welcome.do?method=index 我的几何不可能那么可爱 时间限制(普通/Java) : 1000 MS/ 3 ...

  9. 牛客网暑期ACM多校训练营(第三场)J 多边形与圆相交的面积

    链接:https://www.nowcoder.com/acm/contest/141/J 题目描述 Eddy has graduated from college. Currently, he is ...

随机推荐

  1. 【DNS域名解析命令】 dig

    dig - DNS lookup utility dig 命令主要用来从 DNS 域名服务器查询主机地址信息. Dig (domain information groper 域名信息搜索)是一个灵活的 ...

  2. FastReport.Net中使用列表和数组作为报表数据源

    大多数现代报告工具允许您使用几乎任何数据库,然而,并不是所有报表工具都能以一个数据源的列表或数组来工作.本文中将展示如何使用FastReport .Net报表工具来实现. 请注意以下重要几点: 清单中 ...

  3. 使用ScriptX控件进行Web横向打印

    一个需求需要采用横向打印,目前采用IE自身的打印功能(WebBrowser.ExecWB控件)很难进行横向设置,默认需要调用document.all.WebBrowser.ExecWB(8,1);打开 ...

  4. Eclipse 全部快捷一览表(具TM全)

    1. 编辑快捷键 编辑快捷键 介绍 psvm + Tab 生成main方法 sout + tab 生成输出语句 Ctrl+X / Ctrl + Y 删除一行 Ctrl+D 复制一行 Ctrl+/ 或 ...

  5. Appium-desktop 元素定位

    1.打开 appium-desktop ,点击 start session 2.打开后,点击屏幕右上角的搜索按钮 3.然后会打开配置页面,在本地服务配置信息同上面写的代码链接配置.填入正确的信息后,点 ...

  6. Python(Pyautogui 模块)

    1.安装 pyautogui 模块 pip install pyautogui 2.pyautogui 模块相关操作 鼠标操作 # 获取屏幕宽和高 w,h = pyautogui.size() # 在 ...

  7. Cordova 浅析架构的原理

    因为项目使用了Cordova,也使用了很长时间.至于有很多hybride框架,为什么我们使用Cordova,这里不做过多的叙述,我们也是根据项目需求来选定的,需要及时更新.还要输出别人SDK等.没有最 ...

  8. window下用notepad++编辑了脚本文件然后放在linux报错显示无法运行

    首先vi :set ff 查看文件类型 接着 下载dos2unix  root用户下yum -y install dos2unix 然后 dos2unix 文件.sh 转换格式  接着在正常启动即可

  9. 【Kafka】消息队列相关知识

    目录 概述 常用消息队列 常用消息队列对比 应用场景 消息队列的两种模式 概述 消息(Message) 是指在应用系统之间传递的数据.消息可以非常简单,比如只包含文本字符串,也可以更复杂,可能包含嵌入 ...

  10. Linux内核驱动学习(八)GPIO驱动模拟输出PWM

    文章目录 前言 原理图 IO模拟输出PWM 设备树 驱动端 调试信息 实验结果 附录 前言 上一篇的学习中介绍了如何在用户空间直接操作GPIO,并写了一个脚本可以产生PWM.本篇的学习会将写一个驱动操 ...