POJ 2986 A Triangle and a Circle 圆与三角形的公共面积
计算几何模板
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm> const double eps = 1e-;
const double pi = acos(-1.0); int dcmp(double x)
{
if(x > eps) return ;
return x < -eps ? - : ;
} struct Point
{
double x, y;
Point()
{
x = y = ;
}
Point(double a, double b)
{
x = a, y = b;
}
inline void read()
{
scanf("%lf%lf", &x, &y);
}
inline Point operator-(const Point &b)const
{
return Point(x - b.x, y - b.y);
}
inline Point operator+(const Point &b)const
{
return Point(x + b.x, y + b.y);
}
inline Point operator*(const double &b)const
{
return Point(x * b, y * b);
}
inline double dot(const Point &b)const
{
return x * b.x + y * b.y;
}
inline double cross(const Point &b, const Point &c)const
{
return (b.x - x) * (c.y - y) - (c.x - x) * (b.y - y);
}
inline double Dis(const Point &b)const
{
return sqrt((*this - b).dot(*this - b));
}
inline bool InLine(const Point &b, const Point &c)const//三点共线
{
return !dcmp(cross(b, c));
}
inline bool OnSeg(const Point &b, const Point &c)const//点在线段上,包括端点
{
return InLine(b, c) && (*this - c).dot(*this - b) < eps;
}
}; inline double min(double a, double b)
{
return a < b ? a : b;
}
inline double max(double a, double b)
{
return a > b ? a : b;
}
inline double Sqr(double x)
{
return x * x;
}
inline double Sqr(const Point &p)
{
return p.dot(p);
} Point LineCross(const Point &a, const Point &b, const Point &c, const Point &d)
{
double u = a.cross(b, c), v = b.cross(a, d);
return Point((c.x * v + d.x * u) / (u + v), (c.y * v + d.y * u) / (u + v));
} double LineCrossCircle(const Point &a, const Point &b, const Point &r,
double R, Point &p1, Point &p2)
{
Point fp = LineCross(r, Point(r.x + a.y - b.y, r.y + b.x - a.x), a, b);
double rtol = r.Dis(fp);
double rtos = fp.OnSeg(a, b) ? rtol : min(r.Dis(a), r.Dis(b));
double atob = a.Dis(b);
double fptoe = sqrt(R * R - rtol * rtol) / atob;
if(rtos > R - eps) return rtos;
p1 = fp + (a - b) * fptoe;
p2 = fp + (b - a) * fptoe;
return rtos;
} double SectorArea(const Point &r, const Point &a, const Point &b, double R)
//不大于180度扇形面积,r->a->b逆时针
{
double A2 = Sqr(r - a), B2 = Sqr(r - b), C2 = Sqr(a - b);
return R * R * acos((A2 + B2 - C2) * 0.5 / sqrt(A2) / sqrt(B2)) * 0.5;
} double TACIA(const Point &r, const Point &a, const Point &b, double R)
//TriangleAndCircleIntersectArea,逆时针,r为圆心
{
double adis = r.Dis(a), bdis = r.Dis(b);
if(adis < R + eps && bdis < R + eps) return r.cross(a, b) * 0.5;
Point ta, tb;
if(r.InLine(a, b)) return 0.0;
double rtos = LineCrossCircle(a, b, r, R, ta, tb);
if(rtos > R - eps) return SectorArea(r, a, b, R);
if(adis < R + eps) return r.cross(a, tb) * 0.5 + SectorArea(r, tb, b, R);
if(bdis < R + eps) return r.cross(ta, b) * 0.5 + SectorArea(r, a, ta, R);
return r.cross(ta, tb) * 0.5 +
SectorArea(r, a, ta, R) + SectorArea(r, tb, b, R);
} const int N = ; Point p[N]; double SPICA(int n, Point r, double R)//SimplePolygonIntersectCircleArea
{
int i;
double res = , if_clock_t;
for(i = ; i < n; ++ i)
{
if_clock_t = dcmp(r.cross(p[i], p[(i + ) % n]));
if(if_clock_t < ) res -= TACIA(r, p[(i + ) % n], p[i], R);
else res += TACIA(r, p[i], p[(i + ) % n], R);
}
return fabs(res);
} double r; int main()
{
while (~scanf("%lf%lf", &p[].x, &p[].y))
{
for (int i = ; i < ; i++)
p[i].read();
scanf("%lf", &r);
printf("%.2f\n", SPICA(, p[], r));
}
return ;
}
POJ 2986 A Triangle and a Circle 圆与三角形的公共面积的更多相关文章
- POJ 2986 A Triangle and a Circle
题意:给定一个三角形,以及一个圆的圆心坐标和半径,求圆和三角形的相交面积. 思路: 用三角剖分,三角形上每个线段都变成这个线段与圆心的三角形,然后算出每个三角形与圆的相交面积,然后根据有向面积的正负累 ...
- POJ 2986 A Triangle and a Circle(三角形和圆形求交)
Description Given one triangle and one circle in the plane. Your task is to calculate the common are ...
- poj2986A Triangle and a Circle&&poj3675Telescope(三角形剖分)
链接 2986是3675的简化版,只有一个三角形. 这题主要在于求剖分后三角形与圆的相交面积,需要分情况讨论. 具体可以看此博客 http://hi.baidu.com/billdu/item/703 ...
- POJ 2546 Circular Area(两个圆相交的面积)
题目链接 题意 : 给你两个圆的半径和圆心,让你求两个圆相交的面积大小. 思路 : 分三种情况讨论 假设半径小的圆为c1,半径大的圆为c2. c1的半径r1,圆心坐标(x1,y1).c2的半径r2,圆 ...
- poj 1163 The Triangle &poj 3176 Cow Bowling (dp)
id=1163">链接:poj 1163 题意:输入一个n层的三角形.第i层有i个数,求从第1层到第n层的全部路线中.权值之和最大的路线. 规定:第i层的某个数仅仅能连线走到第i+1层 ...
- 简单几何(圆与多边形公共面积) UVALive 7072 Signal Interference (14广州D)
题目传送门 题意:一个多边形,A点和B点,满足PB <= k * PA的P的范围与多边形的公共面积. 分析:这是个阿波罗尼斯圆.既然是圆,那么设圆的一般方程:(x + D/2) ^ 2 + (y ...
- (点到线段的最短距离)51nod1298 圆与三角形
1298 圆与三角形 给出圆的圆心和半径,以及三角形的三个顶点,问圆同三角形是否相交.相交输出"Yes",否则输出"No".(三角形的面积大于0). 收起 ...
- 51nod-1298 圆与三角形(计算几何超详解)
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1298 给出圆的圆心和半径,以及三角形的三个顶点,问圆同三角形是 ...
- hdu 3264(枚举+二分+圆的公共面积)
Open-air shopping malls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
随机推荐
- linux复制多个文件到文件夹
linux复制多个文件到文件夹 cp file1 file2 file3 directory即将文件file1 file2 file3复制到directory
- BZOJ 4146 [AMPPZ2014] Divisors 解题报告
这个题感觉比较小清新... 我们记录每个数出现的次数 $T_i$. 首先依次枚举每个数字,令 $ans = ans + T_i \times (T_i - 1)$,然后枚举这个数的倍数,令 $ans ...
- SQLite数据库简介(转)
大家好,今天来介绍一下SQLite的相关知识,并结合Java实现对SQLite数据库的操作. SQLite是D.Richard Hipp用C语言编写的开源嵌入式数据库引擎.它支持大多数的SQL92标准 ...
- SQL注入file导入常用手段
在注入过程中,如果存在注入点,可以直接导入一句话或者上传页面.过程中我们主要是利用into outfile函数进行上传.此处介绍两种关于into outfile利用的方式. 第一种直接将select内 ...
- JAVA面试题:Spring中bean的生命周期
Spring 中bean 的生命周期短暂吗? 在spring中,从BeanFactory或ApplicationContext取得的实例为Singleton,也就是预设为每一个Bean的别名只能维持一 ...
- Codeforces Round #242 (Div. 2) A~C
题目链接 A. Squats time limit per test:1 secondmemory limit per test:256 megabytesinput:standard inputou ...
- jmeter 响应结果分析二
转自:http://www.cnblogs.com/Carrie_Liang/archive/2008/11/10/1330997.html 前文再续,续接上一回.上一篇讲了如何利用Assertion ...
- Java泛型:类型擦除
类型擦除 代码片段一 Class c1 = new ArrayList<Integer>().getClass(); Class c2 = new ArrayList<String& ...
- Nginx-location配置指南
语法规则: location [=|~|~*|^~] /uri/ { … } = 开头表示精确匹配 ^~ 开头表示uri以某个常规字符串开头,理解为匹配 url路径即可.nginx不对url做编码,因 ...
- 雷军北大演讲:除了聪明和勤奋我们还需要什么(关键是有了梦想以后,你能不能把这个东西付诸实践)good
雷军北大演讲:除了聪明和勤奋我们还需要什么 昨天我在乌镇参加了全球互联网峰会,在这个会议上有马云,也有苹果公司的高级副总裁,主持人抛出了一个问题,说雷军你说你有一个目标,要用5到10年的时间做智能手机 ...