poj 1269 Intersecting Lines
来源:互联网 发布:为什么矩阵要正交化 编辑:程序博客网 时间:2024/05/16 11:33
直线和直线的位置关系判断:
1)重叠: 判断方法就是四点共线。
2)平行: 判断的方法就是叉积为0 且 四点不共线
3)相交: 交点的坐标就是利用类似定比分点公式的方法;
Code:
/*判断直线和直线位置关系和求交点*/#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<vector>using namespace std;#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)#define DOR(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)#define oo 1<<30#define eps 1e-8#define nMax 500#define pb push_back#define bug puts("OOOOh.....");#define zero(x) (((x)>0?(x):-(x))<eps)int dcmp(double x){ if(fabs(x)<eps) return 0; return x>0?1:-1;}struct point { double x,y; point(double x=0,double y=0): x(x),y(y) {} void read(){ scanf("%lf%lf",&x,&y); } friend point operator -(point const& u,point const& v) { return point(u.x-v.x,u.y-v.y); } friend double operator *(point const& u,point const& v) { return u.x*v.y-u.y*v.x; } friend point operator *(double const& k,point const& v) { return point(k*v.x,k*v.y); } friend point operator /(point const& u,double const& k){ return point(u.x/k,u.y/k); } friend int dots_online(point,point,point);};int dots_online(point a,point b,point c){ return dcmp((a-c)*(b-c))==0; }struct line{ point a,b; line() {} line(point a,point b): a(a),b(b) {} void read() { a.read(),b.read(); } friend int intersection(line,line); friend int parallel(line,line);};int parallel(line l1,line l2){ return dcmp((l1.a-l1.b)*(l2.a-l2.b))==0; }int intersection(line l1,line l2,point &p){ if(dots_online(l1.a,l1.b,l2.a) && dots_online(l1.a,l1.b,l2.b)) return 1; if(parallel(l1,l2)) return 0; double s1 = (l1.a-l2.a)*(l2.b-l2.a); double s2 = (l1.b-l2.a)*(l2.b-l2.a); p = (s1*l1.b-s2*l1.a)/(s1-s2); return 2;}int n;line l1,l2;point p;int main(){#ifndef ONLINE_JUDGE freopen("input.txt","r",stdin);#endif while(~scanf("%d",&n)){ puts("INTERSECTING LINES OUTPUT"); FOR(i,1,n) { l1.read(),l2.read(); switch(intersection(l1,l2,p)){ case 0: puts("NONE");break; case 1: puts("LINE");break; case 2: printf("POINT %.2f %.2f\n",p.x,p.y);break; } } puts("END OF OUTPUT"); } return 0;}
- POJ 1269 Intersecting Lines
- POJ 1269 Intersecting Lines
- poj 1269 Intersecting Lines
- poj 1269 Intersecting Lines
- poj 1269 Intersecting Lines
- POJ 1269 Intersecting Lines
- poj 1269 Intersecting Lines
- POJ 1269 Intersecting Lines
- POJ 1269 Intersecting Lines
- POJ 1269 Intersecting Lines
- poj 1269 Intersecting Lines
- poj 1269 Intersecting Lines
- poj 1269 Intersecting Lines
- poj 1269 Intersecting Lines
- POJ 1269 Intersecting Lines
- poj 1269 Intersecting Lines
- poj 1269 Intersecting Lines
- POJ 1269 Intersecting Lines
- struts2 监听器
- 【图论基础练习】 SCU 2013 Summer Traing 3 - Graph Theory (1) 解题报告
- container_of 理解
- 解决SQLSERVER在还原数据时出现的“FILESTREAM功能被禁用”问题
- hadoop编译WORDCOUNT
- poj 1269 Intersecting Lines
- linux下解压命令大全
- 节约空间的筛素数方法
- iOS 获取一个类的所有方法
- The import android.* cannot be resolved
- S3C2440 电阻式触摸屏
- java.lang.NoClassDefFoundError: org/hibernate/cfg/HbmBinder$SecondPass解决办法 .
- STL中map,set的基本用法示例
- 和菜鸟一起学android4.0.3源码之wifi的简单分析