POJ 1410 Intersection(判断线段是否在矩形面里)
来源:互联网 发布:网络供应商联系方式 编辑:程序博客网 时间:2024/05/18 00:18
题意:给你线段和矩形,问是否相交,或矩形包含线段;
注意:线段相交时,<(0,0),(1,0)> 和<(3,0),(4,0)> 不相交。。。。郁闷死了。。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <queue>using namespace std;const double INF = 1e20;const double EPS = 1e-6;bool zero(double t){return -EPS<t&&t<EPS;}struct cvector{ double x,y; cvector(double a,double b){x=a,y=b;} cvector(){}};cvector operator+(cvector a,cvector b){ return cvector(a.x+b.x,a.y+b.y);}cvector operator-(cvector a,cvector b){ return cvector(b.x-a.x,b.y-a.y);}cvector operator*(double a,cvector b){ return cvector(a*b.x,a*b.y);}double operator*(cvector a,cvector b){ return a.x*b.x+a.y*b.y;}double operator^(cvector a,cvector b){ return a.x*b.y-b.x*a.y;}double length(double t){return t>0?t:-t;}double length(cvector t){return sqrt(t*t);}struct cpoint{ double x,y; cpoint(double a,double b){x=a,y=b;} cpoint(){}};cvector operator-(cpoint a,cpoint b){ return cvector(b.x-a.x,b.y-a.y);}double dist(cpoint a,cpoint b){ return length(b-a);}struct cline{ cpoint a,b;};bool intersect(cline a,cline b){ if(zero((a.a-a.b)^(b.a-b.b))) return false; return ((a.a-b.a)^(b.b-b.a))*((a.b-b.a)^(b.b-b.a))<EPS&& ((b.a-a.a)^(a.b-a.a))*((b.b-a.a)^(a.b-a.a))<EPS;}cpoint st,en;cline b[4],tmp;bool in(cpoint t){ for(int i=0;i<4;i++) if(((t-b[i].a)^(b[i].b-b[i].a))>EPS) { return false; } return true;}int main(){ freopen("in.txt","r",stdin); int cas; scanf("%d",&cas); while(cas--) { scanf("%lf%lf%lf%lf",&tmp.a.x,&tmp.a.y,&tmp.b.x,&tmp.b.y); scanf("%lf%lf%lf%lf",&st.x,&st.y,&en.x,&en.y); if(st.x>en.x) swap(st.x,en.x); if(st.y<en.y) swap(st.y,en.y); b[0].a.x=st.x,b[0].a.y=en.y;b[0].b=en; b[1].a=en;b[1].b.x=en.x,b[1].b.y=st.y; b[2].a=b[1].b;b[2].b=st; b[3].a=st;b[3].b = b[0].a; if(in(tmp.a)||in(tmp.b)) { printf("T\n"); continue; } bool f =false; for(int i=0;i<4;i++) if(intersect(tmp,b[i])) { f = true;break; } if(f) printf("T\n"); else printf("F\n"); } return 0;}
- POJ 1410 Intersection(判断线段是否在矩形面里)
- poj 1410 Intersection 【判断线段 与矩形面是否相交】
- POJ 1410 Intersection (判断线段与矩形是否相交)
- POJ 1410 Intersection (判断线段是否与矩形相交)
- POJ 1410 Intersection(判断线段与矩形是否相交)
- POJ 1410 Intersection(判断线段和矩形是否相交)
- POJ 1410 Intersection(判断线段与矩形是否相交)
- poj 1410 Intersection(判断线段是否与实心矩形相交)
- POJ 1410 Intersection(线段相交&&判断点在矩形内&&坑爹)
- POJ 1410 Intersection(判断线段交和点在矩形内)
- POJ 1410 Intersection(判断线段交和点在矩形内)
- POJ 1410 Intersection(判断线段交和点在矩形内)
- POJ 1410 Intersection 判断矩形和线段相交
- POJ 1410Intersection 计算几何 判断线段与矩形位置
- POJ 1410 || Intersection(线段矩形相交
- UVA 191 || Intersection (判断线段是否与矩形相交
- poj-1410 判断矩形和线段是否相交
- poj 1410 判断线段和矩形是否相交
- 2012ESRI中国用户大会有感
- 如何有效地报告Bug
- hdu 3339 In Action
- 修改MFC窗口标题和图标
- Silverlight嵌入Html并调用该Html中的Javascript
- POJ 1410 Intersection(判断线段是否在矩形面里)
- 暑假总结
- 程序员面试 ---- struct和class的区别
- Python2入门教程 超详细1小时学会Python
- 浅谈过载保护(转自腾讯大讲堂)
- 华清远见ARM A8 Uboot流程
- JDBC调用存储过程
- 多重继承虚基类 vc6.0编译通过
- Java动态调用方法