poj 3675 Telescope(三角剖分求多边形和圆交面积)
来源:互联网 发布:京东股票数据 编辑:程序博客网 时间:2024/05/21 11:13
Description
Updog is watching a plane object with a telescope. The field of vision in the telescope can be described as a circle. The center is at the origin and the radius is R. The object can be seen as a simple polygon of N vertexes. Updog wants to know the area of the part of the object that can be seen in the telescope.
Input
The input will contain several test cases. For each case:
The first line contains only one real number R.
The second line contains an integer N. The following N lines contain two real numbers xi and yi each, which describe the coordinates of a vertex. Two vertexes in adjacent lines are also adjacent on the polygon.
Constraints: 3 ≤ N ≤50, 0.1 ≤ R ≤1000, -1000 ≤ xi, yi ≤ 1000
Output
For each test case, output one real number on a separate line, which is the area of the part that can be seen. The result should be rounded to two decimal places.
Sample Input
1030 2010 0-10 0
Sample Output
144.35
Source
#include<stdio.h>#include<algorithm>#include<math.h>#define eps 1e-8using namespace std;struct point{ double x,y; point(){} point(double x_,double y_):x(x_),y(y_){}}p[58],tp[2],origin;double r,area;int n;double MIN(double x,double y){ return x<y?x:y; }double MAX(double x,double y){ return x>y?x:y; }double cross(point p1,point p2,point p3){ return (p2.x-p1.x)*(p3.y-p1.y)-(p3.x-p1.x)*(p2.y-p1.y);}double dot(point p1,point p2){ return p1.x*p2.x+p1.y*p2.y;}double dis(point p1,point p2){ return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));}struct point get_intersect(){ struct point temp=point(tp[0].x-tp[1].x,tp[0].y-tp[1].y); struct point vec=point(temp.y,-temp.x); struct point origin2=point(origin.x+vec.x,origin.y+vec.y); double a1=tp[0].y-tp[1].y; double b1=tp[1].x-tp[0].x; double c1=(tp[0].x*tp[1].y-tp[1].x*tp[0].y); double a2=origin.y-origin2.y; double b2=origin2.x-origin.x; double c2=(origin.x*origin2.y-origin2.x*origin.y); double tmd=a1*b2-a2*b1; return point((b1*c2-b2*c1)/tmd,(a2*c1-a1*c2)/tmd);};int on_line(point p0,point p1,point p2){ if(p0.x>MAX(p1.x,p2.x)) return 0; if(p0.x<MIN(p1.x,p2.x)) return 0; if(p0.y>MAX(p1.y,p2.y)) return 0; if(p0.y<MIN(p1.y,p2.y)) return 0; return 1;}double get_area(){ double len0=dis(origin,tp[0]); double len1=dis(origin,tp[1]); double angle=acos(dot(tp[0],tp[1])/len0/len1); struct point inter=get_intersect(); double disinter=dis(inter,origin); double sgn=cross(origin,tp[0],tp[1])<0?-1:1; double res=0; if(angle<eps||fabs(cross(origin,tp[0],tp[1]))<eps) return 0; else if(len0<r+eps&&len1<r+eps) { res=fabs(cross(origin,tp[0],tp[1]))/2.0; } else if(len0<r-eps||len1<r-eps) { if(len1<r-eps) { swap(tp[0],tp[1]); swap(len0,len1); } double dis01=dis(tp[0],tp[1]); struct point mov=point((tp[1].x-tp[0].x)/dis01,(tp[1].y-tp[0].y)/dis01); double len=sqrt(r*r-disinter*disinter); struct point interpoint; interpoint=point(inter.x+mov.x*len,inter.y+mov.y*len); double angle0=acos(dot(tp[1],interpoint)/len1/r); res=r*r*angle0/2.0; res+=fabs(cross(origin,interpoint,tp[0]))/2.0; } else { int flag=on_line(inter,tp[0],tp[1]); res=r*r*angle/2.0; if(flag&&disinter<r) { double tangle=2*acos(disinter/r); res-=r*r*tangle/2.0; res+=r*disinter*sin(tangle/2.0); } } return res*sgn;}void solve(){ area=0; for(int i=1;i<=n;i++) { tp[0]=p[i],tp[1]=p[i+1]; area+=get_area(); }}int main(){ //freopen("t.txt","r",stdin); origin=point(0,0); while(scanf("%lf%d",&r,&n)>0) { for(int i=1;i<=n;i++) scanf("%lf%lf",&p[i].x,&p[i].y); p[n+1]=p[1]; solve(); printf("%.2lf\n",fabs(area)); } return 0;}
- poj 3675 Telescope(三角剖分求多边形和圆交面积)
- poj 3675 Telescope 圆和多边形的公共面积
- 求圆和多边形的面积交
- HDU 3982 (半平面交 多边形和圆面积交)
- POJ 3384 Feng Shui (半平面交求多边形内两个圆最大面积)
- 三角剖分·圆和多边形的交
- [BZOJ 2618][CQOI 2006]凸多边形(半平面交+三角剖分求多边形面积)
- HDU 2892 (平面几何 圆和多边形面积交)
- HDU 5230 (计算几何 圆和多边形面积交)
- HDOJ 5130 Signal Interference(圆与多边形面积交)
- HDU 5134 Highways (圆与多边形面积交)
- 简单多边形与圆的交面积
- 模板-多边形与圆的面积交
- lightoj1130【圆与多边形面积交】
- 计算多边形与圆的面积交
- 多边形与圆面积交 模板
- 圆与多边形求交面积
- POJ 3675/2986(Telescope/A Triangle and a Circle-三角形与圆的面积并)
- 在windows上安装common lisp开发环境
- 黑马程序员_面向对象
- 变量存储类型
- ubuntu下安装环境 opencv&opencl
- AS3.0学习笔记--值类型和引用类型的区别
- poj 3675 Telescope(三角剖分求多边形和圆交面积)
- 对CSDN高校俱乐部的建议
- C 语言(C99) 对 64 位整数类型的支持(云风的blog)
- Linux strace命令
- javascript 动态参数简单demo
- 在论坛中出现的各种疑难问题:性能优化
- 一个人的创业时代
- oracle proc配置
- 网赚平台Clixsense+手机号邮箱短信提醒调查实现轻松网赚