圆形与矩形截面的面积

三角仍然可以做到这一点

代码:

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
using namespace std; const double eps = 1e-8;
const double pi = acos(-1.0); int dcmp(double x)
{
if(x > eps) return 1;
return x < -eps ? -1 : 0;
} struct Point
{
double x, y;
Point(){x = y = 0;}
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 = 505; Point p[N], o; double SPICA(int n, Point r, double R)//SimplePolygonIntersectCircleArea
{
int i;
double res = 0, if_clock_t;
for(i = 0; i < n; ++ i)
{
if_clock_t = dcmp(r.cross(p[i], p[(i + 1) % n]));
if(if_clock_t < 0) res -= TACIA(r, p[(i + 1) % n], p[i], R);
else res += TACIA(r, p[i], p[(i + 1) % n], R);
}
return fabs(res);
} double r; int main() {
int bo = 0;
while (~scanf("%lf%lf%lf", &o.x, &o.y, &r)) {
if (bo) printf("\n");
else bo = 1;
double x1, y1, x2, y2;
scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
if (x1 > x2) swap(x1, x2);
if (y1 > y2) swap(y1, y2);
p[0] = Point(x1, y1);
p[1] = Point(x1, y2);
p[2] = Point(x2, y2);
p[3] = Point(x2, y1);
printf("%.10f\n", SPICA(4, o, r));
}
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

ZOJ 2675 Little Mammoth(计算几何)的更多相关文章

  1. ZOJ 1696 Viva Confetti 计算几何

    计算几何:按顺序给n个圆覆盖.问最后能够有几个圆被看见.. . 对每一个圆求和其它圆的交点,每两个交点之间就是可能被看到的圆弧,取圆弧的中点,往外扩展一点或者往里缩一点,从上往下推断有没有圆能够盖住这 ...

  2. zoj 3537 区间dp+计算几何

    题意:给定n个点的坐标,先问这些点是否能组成一个凸包,如果是凸包,问用不相交的线来切这个凸包使得凸包只由三角形组成,根据costi, j = |xi + xj| * |yi + yj| % p算切线的 ...

  3. ACM计算几何题目推荐

    //第一期 计算几何题的特点与做题要领: 1.大部分不会很难,少部分题目思路很巧妙 2.做计算几何题目,模板很重要,模板必须高度可靠. 3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面 ...

  4. July 【补题】

    A(zoj 3596) bfs,记忆搜都可以, 按余数来记录状态. B(zoj 3599) 博弈,跳过 C(zoj 3592) 简单dp,题意不好懂 D(zoj 3602) 子树哈希, 对根的左右儿子 ...

  5. ZOJ 3157 Weapon --计算几何+树状数组

    题意:给一些直线,问这些直线在直线x=L,x=R之间有多少个交点. 讲解见此文:http://blog.sina.com.cn/s/blog_778e7c6e0100q64a.html 首先将直线分别 ...

  6. ZOJ 3203 Light Bulb (三分+计算几何)

    B - Light Bulb Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit ...

  7. ZOJ 1081 Within(点是否在多边形内)| 计算几何

    ZOJ 1081 Within 我使用的是"射线法":从该点出发,作一条向左的水平射线,与多边形的边的交点有奇数个则点在多边形内. 需要注意的点: 如果点在多边形的边上特判. 考虑 ...

  8. zoj 1081:Points Within(计算几何,判断点是否在多边形内,经典题)

    Points Within Time Limit: 2 Seconds      Memory Limit: 65536 KB Statement of the Problem Several dra ...

  9. zoj 3716 Ribbon Gymnastics【神奇的计算几何】

    题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3716 来源:http://acm.hust.edu.cn/vjudg ...

随机推荐

  1. ORACLE 实验一

    实验一:数据定义 实验学时:4学时 实验类型:综合型 实验要求:必修 一.实验目的 1.熟悉Oracle的client配置: 2.掌握SQL Plus的使用: 3.掌握SQL模式定义语句,定义相关的表 ...

  2. 阿里2015在线研发project师笔试题(部分)

    今天lz去阿里的在线笔试打了一把酱油,因为lz的水平有限,时间太他么紧张了.以下把记下来的题给大家分享一下.选择题总共20道,前十题截了图,后面感觉太费时就没有再截了,凭记忆记下了两道.附加题都记录下 ...

  3. LINQ之路(2):LINQ to SQL本质

    LINQ之路(2):LINQ to SQL本质 在前面一篇文章中回顾了LINQ基本语法规则,在本文将介绍LINQ to SQL的本质.LINQ to SQL是microsoft针对SQL Server ...

  4. 【Nginx】显示器port管理

    监听port属于server虚拟主机,由server{}块内的listen配置项决定. 也就是说,在server{}块配置项内定义了该虚拟主机所要监听的port. 在处理配置文件http块内main级 ...

  5. k8s with flanneld

    三台机器 kmaster 192.168.1.201 kslave202 192.168.1.202 kslave203 192.168.1.203 安装好k8s 1. 在Node机器上安装flann ...

  6. cygwin的163镜像(转)

    国内的cygwin源镜像: 1.163源 http://mirrors.163.com/.help/cygwin.html 收录架构 x86 x86_64 收录版本 所有版本 更新时间 每天更新一次 ...

  7. 好记性不如烂笔头85-spring3学习(6)-BeanFactory 于bean生命周期

    假设BeanFactory为了产生.管理Bean, 一个Bean从成立到毁灭.它会经过几个阶段运行. 据我所知,一般bean包括在生命周期:设定,初始化,使用阶段,四个核心阶段销毁. 1.@Bean的 ...

  8. Navicat工具Oracle数据库复制 or 备用、恢复功能(评论都在谈论需要教)

    GXPT它是一个分布式系统,该系统包括一个临时许可系统.基本系统.教学评价体系.考试系统,每个系统都有自己的oracle数据库.统,而评教系统的正常须要借助于权限系统和基础系统,详细的业务这里就不多解 ...

  9. printf交替使用

    今天附带printf一些替代实现. 转载请注明出处:http://blog.csdn.net/u010484477谢谢^_^ 我们总是用printf做各种输出语句: printf("%d&q ...

  10. Swift使用单个案件管理FMDB数据库

    下班... 抢 我曾经Swift使用单一个案管理FMDB数据库的方法共享出来: // Created by 秦志伟 on 14-6-12. import UIKit class ZWDBManager ...