POJ 1410 Intersection(线段与矩形相交)
来源:互联网 发布:数据冗余怎么念 编辑:程序博客网 时间:2024/04/30 08:18
判断矩形和线段是否相交,没什么说的,
正确理解题意中相交的定义
具体代码:
#include<iostream>#include<stdio.h>#include<cmath>using namespace std;typedef struct{ double x; double y;}point;point rect[4];point line[2];double multi(point p0, point p1, point p2){ return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);}bool is_cross(point s1,point e1,point s2,point e2)//判断线段是否相交(非规范相交){ return max(s1.x,e1.x) >= min(s2.x,e2.x)&&max(s2.x,e2.x) >= min(s1.x,e1.x)&& max(s1.y,e1.y) >= min(s2.y,e2.y)&&max(s2.y,e2.y) >= min(s1.y,e1.y)&& multi(s1,e1,s2)*multi(s1,e1,e2) <= 0&&multi(s2,e2,s1)*multi(s2,e2,e1) <= 0;}int main(){ int i,j; int t; bool flag; double bigx,smallx,bigy,smally; scanf("%d",&t); while(t--) { flag=true; scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&line[0].x,&line[0].y,&line[1].x,&line[1].y,&rect[3].x,&rect[3].y,&rect[1].x,&rect[1].y); rect[0].x=rect[3].x; rect[0].y=rect[1].y; rect[2].x=rect[1].x; rect[2].y=rect[3].y; bigx=max(rect[3].x,rect[1].x),smallx=min(rect[3].x,rect[1].x),bigy=max(rect[3].y,rect[1].y),smally=min(rect[3].y,rect[1].y); if(is_cross(line[0],line[1],rect[0],rect[1])&&is_cross(line[0],line[1],rect[1],rect[2])&&is_cross(line[0],line[1],rect[2],rect[3])&&is_cross(line[0],line[1],rect[3],rect[0])) { flag=false; printf("T\n"); continue; } if((line[0].x>smallx&&line[0].x<bigx&&line[0].y>smally&&line[0].y<bigy)||(line[1].x>smallx&&line[1].x<bigx&&line[1].y>smally&&line[1].y<bigy)) { flag=false; printf("T\n"); continue; } printf("F\n"); } return 0;}
0 0
- poj 1410 Intersection(线段与矩形相交)
- POJ 1410 Intersection(线段与矩形相交)
- POJ 1410 Intersection(判断线段与矩形是否相交)
- POJ 1410 Intersection (判断线段与矩形是否相交)
- POJ 1410 Intersection (判断线段是否与矩形相交)
- POJ 1410 Intersection(判断线段与矩形是否相交)
- poj 1410 Intersection 【判断线段 与矩形面是否相交】
- POJ 1419 Intersection (判线段与矩形相交)
- POJ 1410 || Intersection(线段矩形相交
- POJ 1410 Intersection(判断线段和矩形是否相交)
- poj 1410 Intersection(判断线段是否与实心矩形相交)
- POJ 1410 Intersection 判断矩形和线段相交
- poj1410 Intersection 线段与矩形相交
- poj 1410 Intersection (线段相交判定)
- poj 1410 Intersection (判矩形和线段相交。。细节多)
- poj 1410 Intersection(判矩形和线段相交。。细节多)
- POJ 1410 Intersection(线段相交&&判断点在矩形内&&坑爹)
- poj 1410 矩形与线段相交判断
- Android的SDK与ADT不匹配问题
- Android SDK在线更新镜像服务器ZZ
- 源代码管理器git与svn辨析
- IOS 面试总结
- hdu2665/poj2104;poj2761 区间第k小 函数式线段树
- POJ 1410 Intersection(线段与矩形相交)
- 约瑟夫环问题
- 将一个数字字符串转换成这个字符串对应的数字(包括正浮点数、负浮点数)
- 算法学习 - 求二叉树的宽度
- Xcode工程中ARC的开启和禁止
- SQL优化大全
- Matlab/OpenCV自己实现Harris特征点提取和匹配
- nyoj1080年龄排序(这道题的方法值得学习---一开始真没想到)
- 几个概念让你初步了解智能车比赛