POJ 2546 & ZOJ 1597 Circular Area(求两圆相交的面积 模板)
题目链接:
id=2546
ZOJ: problemId=597" target="_blank">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=597
Description
Input
Output
Sample Input
20.0 30.0 15.0 40.0 30.0 30.0
Sample Output
608.366
Source
题意:
求两圆相交的面积!
直接上模板
代码例如以下:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
//#include <complex>
//#include <iomanip>
using namespace std;
const double eps = 1e-8;
const double PI = acos(-1.0); int sgn(double x)
{
if(fabs(x) < eps) return 0;
if(x < 0) return - 1;
else return 1;
}
struct Point
{
double x, y;
Point(){}
Point(double _x, double _y)
{
x = _x; y = _y;
}
Point operator -( const Point &b) const
{
return Point(x - b. x, y - b. y);
}
//叉积
double operator ^ (const Point &b) const
{
return x*b. y - y*b. x;
}
//点积
double operator * (const Point &b) const
{
return x*b. x + y*b. y;
}
//绕原点旋转角度B(弧度值),后x,y的变化
void transXY(double B)
{
double tx = x,ty = y;
x = tx* cos(B) - ty*sin(B);
y = tx* sin(B) + ty*cos(B);
}
};
//*两点间距离
double dist( Point a, Point b)
{
return sqrt((a-b)*(a- b));
}
//两个圆的公共部分面积
double Area_of_overlap(Point c1, double r1, Point c2, double r2)
{
double d = dist(c1,c2);
if(r1 + r2 < d + eps) return 0;
if(d < fabs(r1 - r2) + eps)
{
double r = min(r1,r2);
return PI*r*r;
}
double x = (d*d + r1*r1 - r2*r2)/(2*d);
double t1 = acos(x / r1);
double t2 = acos((d - x)/r2);
return r1*r1*t1 + r2*r2*t2 - d*r1*sin(t1);
} int main()
{
double x1, y1, r1, x2, y2, r2;
while(~scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&r1,&x2,&y2,&r2))
{
Point c1, c2;
c1.x = x1;
c1.y = y1;
c2.x = x2;
c2.y = y2;
double ans = Area_of_overlap(c1,r1,c2,r2);
printf("%.3lf\n",ans);
//cout<<setiosflags(ios::fixed)<<setprecision(3)<<ans<<endl;
}
return 0;
}
POJ 2546 & ZOJ 1597 Circular Area(求两圆相交的面积 模板)的更多相关文章
- 求两圆相交部分面积(C++)
已知两圆圆心坐标和半径,求相交部分面积: #include <iostream> using namespace std; #include<cmath> #include&l ...
- hdu 5120 (求两圆相交的面积
题意:告诉你两个圆环,求圆环相交的面积. /* gyt Live up to every day */ #include<cstdio> #include<cmath> #in ...
- hdu5858 Hard problem(求两圆相交面积)
题目传送门 Hard problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- poj2546Circular Area(两圆相交面积)
链接 画图推公式 这两种情况 都可用一种公式算出来 就是两圆都求出圆心角 求出扇形的面积减掉三角形面积 #include <iostream> using namespace std; # ...
- POJ 2546 Circular Area(两个圆相交的面积)
题目链接 题意 : 给你两个圆的半径和圆心,让你求两个圆相交的面积大小. 思路 : 分三种情况讨论 假设半径小的圆为c1,半径大的圆为c2. c1的半径r1,圆心坐标(x1,y1).c2的半径r2,圆 ...
- 两圆相交求面积 hdu5120
转载 两圆相交分如下集中情况:相离.相切.相交.包含. 设两圆圆心分别是O1和O2,半径分别是r1和r2,设d为两圆心距离.又因为两圆有大有小,我们设较小的圆是O1. 相离相切的面积为零,代码如下: ...
- [poj] 1269 [zoj] 1280 Interesting Lines || 求两直线交点
POJ原题 ZOJ原题 多组数据.每次给出四个点,前两个点确定一条直线,后两个点确定一条直线,若平行则输出"NONE",重合输出"LINE",相交输出" ...
- ZOJ 1280 Interesting Lines | 求两直线交点
原题: 求两直线交点 思路借鉴于:http://blog.csdn.net/zxy_snow/article/details/6341282 感谢大佬 #include<cstdio> # ...
- UVa 10674 (求两圆公切线) Tangents
题意: 给出两个圆的圆心坐标和半径,求这两个圆的公切线切点的坐标及对应线段长度.若两圆重合,有无数条公切线则输出-1. 输出是按照一定顺序输出的. 分析: 首先情况比较多,要一一判断,不要漏掉. 如果 ...
随机推荐
- 利用overflow-x实现横向滚动的xiaoguo
在进行app开发中经常遇到横向滚动的效果,相信很多人都是用js写的吧,其实用css的overflow-x也可以写出啦哦~~~ (1)介绍overflow-x: 1)浏览器支持 所有主流浏览器都支持 o ...
- str和unicode类
在py2中,分为两类,str和unicode 而在py3中,分为两类,byte和str py2中的str等同于py3中的byte 首先明确一点,我们编辑好一段文本,python并不知道我们的文本是以什 ...
- State Estimation for Robotics (Tim Barfoot) exercises Answers
Here are some exercises answers for State Estimation for Robotics, which I did in June, 2017. The bo ...
- sort命令的k选项大讨论【转】
本原创文章属于<Linux大棚>博客,博客地址为http://roclinux.cn.文章作者为rocrocket. 为了防止某些网站的恶性转载,特在每篇文章前加入此信息,还望读者体谅. ...
- mitmproxy实践
首先附上github地址:https://github.com/mitmproxy/mitmprox,上面的内容永远是最新的 作为一名测试穿戴设备相关app的工程师,与数据打交道是常事,那么,如果想要 ...
- 公共语言运行库(CLR)开发系列课程(3):COM Interop基础 学习笔记
上章地址 什么是COM Component Object Model 组建对象模型 基于接口(Interface) 接口=协议 IID 标识接口 V-table 虚表 方式调用 单继承 对象(Obje ...
- Project Euler Problem5
Smallest multiple Problem 5 2520 is the smallest number that can be divided by each of the numbers f ...
- sphinx 同时使用多个索引进行检索探究
2014年2月15日 11:24:34 结论: 1.一次性使用多个索引进行查询的时候,返回的结果集中的fields字段没有什么清楚的意义(也没有找到文档对它的说明) 2.如果程序中一次搜索使用了多个索 ...
- 配置Eclipse编写HTML/JS/CSS/JSP页面的自动提示
我们平时用eclipse开发jsp页面时智能提示效果不太理想,今天用了两个小时发现了eclipse也可以像Visual Studio 2008那样完全智能提示HTML/JS/CSS代码,使用eclip ...
- vue项目使用vw单位适配移动端方法
传送门: https://blog.csdn.net/zjw0742/article/details/79337336