计算几何模板

 #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 圆与三角形的公共面积的更多相关文章

  1. POJ 2986 A Triangle and a Circle

    题意:给定一个三角形,以及一个圆的圆心坐标和半径,求圆和三角形的相交面积. 思路: 用三角剖分,三角形上每个线段都变成这个线段与圆心的三角形,然后算出每个三角形与圆的相交面积,然后根据有向面积的正负累 ...

  2. 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 ...

  3. poj2986A Triangle and a Circle&&poj3675Telescope(三角形剖分)

    链接 2986是3675的简化版,只有一个三角形. 这题主要在于求剖分后三角形与圆的相交面积,需要分情况讨论. 具体可以看此博客 http://hi.baidu.com/billdu/item/703 ...

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

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

  5. poj 1163 The Triangle &amp;poj 3176 Cow Bowling (dp)

    id=1163">链接:poj 1163 题意:输入一个n层的三角形.第i层有i个数,求从第1层到第n层的全部路线中.权值之和最大的路线. 规定:第i层的某个数仅仅能连线走到第i+1层 ...

  6. 简单几何(圆与多边形公共面积) UVALive 7072 Signal Interference (14广州D)

    题目传送门 题意:一个多边形,A点和B点,满足PB <= k * PA的P的范围与多边形的公共面积. 分析:这是个阿波罗尼斯圆.既然是圆,那么设圆的一般方程:(x + D/2) ^ 2 + (y ...

  7. (点到线段的最短距离)51nod1298 圆与三角形

    1298 圆与三角形 给出圆的圆心和半径,以及三角形的三个顶点,问圆同三角形是否相交.相交输出"Yes",否则输出"No".(三角形的面积大于0).   收起 ...

  8. 51nod-1298 圆与三角形(计算几何超详解)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1298 给出圆的圆心和半径,以及三角形的三个顶点,问圆同三角形是 ...

  9. hdu 3264(枚举+二分+圆的公共面积)

    Open-air shopping malls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/ ...

随机推荐

  1. 基于局部敏感哈希的协同过滤推荐算法之E^2LSH

    需要代码联系作者,不做义务咨询. 一.算法实现 基于p-stable分布,并以‘哈希技术分类’中的分层法为使用方法,就产生了E2LSH算法. E2LSH中的哈希函数定义如下: 其中,v为d维原始数据, ...

  2. Android 环境搭建 版本问题

    jdk1.6 1.7  eclipse 3.7.2    SDK-r12 ADT 12 SDK和ADT必须配套 搭建环境需要四个软件: 1.JDK(这是最新版本jdk1.7官方下载地址:http:// ...

  3. linux ubuntu关于U盘的安装 开机启动u盘的时候出现/casper/vmlinuz.efi: file not found

    将u盘下的/casper/vmlinuz文件添加一个后缀.efi即可. 重启再装.

  4. BZOJ 3123 SDOI2013 森林

    首先对于查询操作就是裸的COT QAQ 在树上DFS建出主席树就可以了 对于连接操作,我们发现并没有删除 所以我们可以进行启发式合并,每次将小的树拍扁插入大的树里并重构即可 写完了之后第一个和第二个点 ...

  5. [itint5]摆放窗口

    http://www.itint5.com/oj/#47 一种做法是:把矩形所占的方格都设为-1,就是个最大子矩阵和问题.复杂度o(w^2*h)或o(w*h^2),空间W*H猜想应用场景是:电脑屏幕上 ...

  6. C++遍历目录,并把目录里超过7天的文件删除(跨平台windows&linux)

    C++遍历目录,并把目录里超过7天的文件删除,适用于项目里删除过期的日志,或者视频文件. 在windows和linux下测试通过. windows测试结果: linux测试结果: 源码: #inclu ...

  7. forks rate异常

    一.收到nagios Current_load报警短信

  8. PHP判断日期是不是今天 判断日期是否为当天

    <?php /** * PHP判断一个日期是不是今天 * 琼台博客 */ echo '<meta charset="utf-8" />'; // 拟设一个日期 $ ...

  9. JavaScript DOM高级程序设计2.3 this--我要坚持到底!

    先从一个例子说起 var sound = 'Roar'; function myOrneryBeast() { this.style.color='green';//window 方法被调用时所属的对 ...

  10. Fast scroller styles

    <!-- Fast scroller styles --> <!-- Drawable to use as the fast scroll thumb. --> <att ...