51nod 1298 圆与三角形(计算几何)
2017-08-03 10:55
465 查看
#include <iostream> #include <cstdio> #include <algorithm> #include <cmath> using namespace std; /* 计算几何 给定圆心坐标、圆半径,三角形三个顶点坐标,判断圆是否与三角形相交 */ const double esp=1e-7; int sgn(double x) { if(fabs(x)<esp) return 0; if(x<0) return -1; else return 1; } struct Point { double x,y; Point() {} Point(double _x,double _y) { x=_x; y=_y; } Point operator -(const Point &b) const { return Point(x-b.x,y-b.y); } double operator ^ (const Point &b) const//叉积 { return x*b.y-y*b.x; } double operator * (const Point &b) const//点积 { return x*b.x+y*b.y; } double distance(Point p)//两点距离 { return hypot(x-p.x,y-p.y); //return (x-p.x)*(x-p.x)+(y-p.y)*(y-p.y); } }; struct Line { Point s,e; Line(){} Line(Point _s,Point _e) { s=_s; e=_e; } double length()//线段长度 { return s.distance(e); } double dispointtoline(Point p)//点到直线距离 { return fabs((p-s)^(e-s))/length(); } double dispointtoseg(Point p)//点到线段距离 { if(sgn((p-s)*(e-s))<0||sgn((p-e)*(s-e))<0) return min(p.distance(s),p.distance(e)); return dispointtoline(p); } }; int main() { int t; scanf("%d",&t); while(t--) { Point c,t[3]; double r; scanf("%lf %lf %lf",&c.x,&c.y,&r); for(int i=0; i<3; i++) { scanf("%lf %lf",&t[i].x,&t[i].y); } Line line[3]; line[0]=Line(t[0],t[1]); line[1]=Line(t[0],t[2]); line[2]=Line(t[1],t[2]); double cnt[3]; for(int i=0; i<3; i++)//圆心到三角形各边的距离 { cnt[i]=line[i].dispointtoseg(c)-r; //cout<<cnt[i]<<endl; } //圆心到三角形各边的距离都大于半径 if(sgn(cnt[0])>0&&sgn(cnt[1])>0&&sgn(cnt[2])>0) { printf("No\n"); } //圆心到三角形各边的距离都小于半径 else if(sgn(cnt[0])<0&&sgn(cnt[1])<0&&sgn(cnt[2])<0)// { bool flag=0; for(int i=0;i<3;i++)//圆心到三角形各顶点的距离 { if(sgn(t[i].distance(c)-r)>=0) { flag=1; break; } } if(flag) { printf("Yes\n"); } else { printf("No\n"); } } else { printf("Yes\n"); } } return 0; }
相关文章推荐
- 51nod 1298 圆与三角形(计算几何)
- 【51Nod】1298 - 圆与三角形(计算几何)
- 51nod 1298 圆与三角形(基础题,计算几何)
- 51Nod 1298:圆与三角形(计算几何)
- 51nod 1298:圆与三角形(计算几何)
- 51nod 1298 圆与三角形 (计算几何)
- 51Nod 1298 圆与三角形 (计算几何)
- 51nod--1298 (计算几何基础)
- 1298 圆与三角形(计算几何)
- 51 nod 1298 圆与三角形 【计算几何】
- 分治 - 计算几何 - BZOJ2458,[BeiJing2011]最小三角形
- 51NOD 1298 圆与三角形
- BZOJ 1845: [Cqoi2005] 三角形面积并 [计算几何 扫描线]
- BZOJ 1845 [Cqoi2005] 三角形面积并 计算几何扫描线
- 51Nod 1298 圆与三角形
- bzoj-2458 2458: [BeiJing2011]最小三角形(计算几何+分治)
- 51nod 1264:线段相交(计算几何)
- CSUOJ 1503: 点到圆弧的距离 [叉积+三角形外心]【计算几何】
- ZOJ-1090-The Circumference of the Circle(计算几何,海伦公式,三角形外接圆半径公式,cout输出小数的一些问题)