线段判交
来源:互联网 发布:mac桌面图标怎么删除 编辑:程序博客网 时间:2024/05/01 00:04
线段判交模版
#include<iostream>using namespace std;inline int max(int a,int b){return a>b? a:b;}inline int min(int a,int b){return a<b? a:b;}struct point{int x;int y;};struct line{point s;point e;}l1,l2;inline int crossProduct(line a, line b) //前一条叉乘后一条{return (a.e.x-a.s.x) * (b.e.y-b.s.y) - (a.e.y-a.s.y) * (b.e.x-b.s.x);}bool judge(line P,line Q);bool judgeRec(line P,line Q);int main(){while(true){cin>>l1.s.x>>l1.s.y>>l1.e.x>>l1.e.y;cin>>l2.s.x>>l2.s.y>>l2.e.x>>l2.e.y;if( judge(l1,l2) )cout<<"相交"<<endl;elsecout<<"不相交"<<endl;}return 0;}bool judge(line P,line Q){if(!judgeRec(P,Q))return false;line L1,L2,L3;L1.s=Q.s;L1.e=P.s;L2=Q;L3.s=Q.s;L3.e=P.e;if( crossProduct(L1,L2)*crossProduct(L2,L3) <0)return false;L1.s=P.s;L1.e=Q.e;L2=P;L3.s=P.s;L3.e=Q.s;if( crossProduct(L1,L2)*crossProduct(L2,L3)<0)return false;return true;}bool judgeRec(line a,line b) //判断以两条线段为对角线的矩形是否相交(快速排除){if( max(a.s.x,a.e.x)>min(b.s.x,b.e.x) && max(b.s.x,b.e.x)>min(a.s.x,a.e.x)&& max(a.s.y,a.e.y)>min(b.s.y,b.e.y) && max(b.s.y,b.e.y)>min(a.s.y,a.e.y) )return true;return false;}
- 线段判交
- HDU 1086(线段判交)
- 线段判交-- POJ 2653
- 计算几何:线段判交模板--ACM
- ZOJ--1010:Area(线段判交问题)
- poj 1127 Jack Straws 线段判交+并查集
- 链表判环、判交问题
- Segments(问题抽象与转化+暴力枚举+线段与直线判交)
- HDOJ 1558 Segment set(并查集 + 线段判交)
- ZOJ--1648:Circuit Board(跨立实验线段判交)
- 判断线面相交问题
- ccsu1359 木棒相交 (叉积线段判交,并查集判断是否属于同一个集合)
- POJ 2653 线段交
- poj1127线段求交
- 【几何】平面线段交
- zoj 2551 判线段相交
- 线段与三角形求交
- 线段求交算法demo
- 讲述一个关于高考的“黑客”故事:用2B铅笔“注入”阅卷系统
- 控制项的资料系结_Master-Details —2
- Linq to sql(六):探究特性
- C#窗体之间传递数据
- Linq to sql(七):并发与事务
- 线段判交
- 在VMware虚拟机上安装Ubuntu 10.04
- Linq to sql(八):继承与关系
- Linq to sql(九):其它补充
- POJ 1088滑雪
- Linq to sql(十):分层构架的例子
- wireshark源代码分析报告之二
- mongodb常用操作
- Linux内存管理中address_space疑惑及解答