poj 1375 Intervals(圆外一点到圆的切点)
2013-09-05 12:50
281 查看
有一个光源,光源到x轴之间有n个圆,求x轴上的圆的阴影的区间。
先求出点到圆的切点,然后根据光源与切点求出直线方程,然后求出直线与x轴的交点,最后判断下线段在x轴上的重叠就行了。
先求出点到圆的切点,然后根据光源与切点求出直线方程,然后求出直线与x轴的交点,最后判断下线段在x轴上的重叠就行了。
#include<iostream> #include<cstdio> #include<string.h> #include<algorithm> #include<math.h> #include<queue> #include<stack> #include<map> #include<vector> #define maxn 505 using namespace std; const int inf=0x7ffffff; const double PI=acos(-1.0); const double eps=1e-8; const double e=2.7182818284590452354; struct point { double x,y; point () {} point (double x,double y): x(x),y(y) {} }p[maxn*4],ans[maxn*4]; struct Circle { point c; double r; Circle() {} Circle( point c, double r ): c(c), r(r) {} point getPoint( double theta ) { return point( c.x + cos(theta)*r, c.y + sin(theta)*r ); } }pc[maxn]; double cross(point a,point b,point op) { return (op.x-a.x)*(op.y-b.y)-(op.x-b.x)*(op.y-a.y); } double dist(point a,point b) { return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } void getTangentPoints( point p, Circle C, point &r1, point &r2) { double dis = dist(p,C.c); double base = atan2( p.y - C.c.y, p.x - C.c.x ); double ang = acos( C.r / dis ); r1 = C.getPoint( base - ang ); r2 = C.getPoint( base + ang ); } double getline(point x,point y) { double a,b,c; a=y.y-x.y; b=x.x-y.x; c=y.x*(x.y-y.y)+y.y*(y.x-x.x); return (-c/a); } bool cmp(point a,point b) { return a.x<b.x; } int main() { int n; point p0; double x0,y0; while(~scanf("%d",&n),n) { scanf("%lf%lf",&x0,&y0); p0=point(x0,y0); for(int i=0;i<n;i++) { point r1,r2; scanf("%lf%lf%lf",&pc[i].c.x,&pc[i].c.y,&pc[i].r); getTangentPoints(p0,pc[i],r1,r2); double u=getline(p0,r1); double v=getline(p0,r2); if(u>v) swap(u,v); ans[i].x=u; ans[i].y=v; } sort(ans,ans+n,cmp); double pre1=ans[0].x; double pre2=ans[0].y; for(int i=1;i<n;i++) { if(ans[i].x>pre2) { printf("%.2lf %.2lf\n",pre1,pre2); pre1=ans[i].x; pre2=ans[i].y; } else pre2=max(ans[i].y,pre2); } printf("%.2lf %.2lf\n\n",pre1,pre2); } return 0; }
相关文章推荐
- POJ 1375 Intervals
- zoj 1309 || poj 1375 Intervals
- POJ 1375 Intervals 笔记
- POJ 1375 过一点求圆切线极角
- poj 1375 Intervals 圆的切线
- poj 1375 Intervals
- POJ 1375 Intervals | 解析几何
- POJ 1375 圆外一点引向圆的切线,直线交点
- poj 1375 Intervals(计算圆的切线)
- POJ 1375 Intervals
- POJ 1375 Intervals 解析几何 求圆的切线
- POJ 1375 Intervals(解析几何)
- POJ1375-Intervals
- POJ 1375 Intervals【过定点做圆的切线】
- POJ 1375 求圆外一点引圆的切线
- POJ 1375 Intervals
- POJ 1201 Intervals
- POJ 1201 Intervals <差分约束系统 + SPFA / 贪心 + 树状数组>
- poj 1201/zoj 1508 intervals 差分约束系统
- POJ 1201 Intervals [差分约束系统]