POJ 1269 Intersecting Lines 判断两直线关系
2017-07-20 10:50
393 查看
用的是初中学的方法
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #define eps 1e-8 using namespace std; struct Point { double x,y; Point() {}; Point(double xx,double yy) { x=xx; y=yy; } }ans; int getCross(Point p1,Point p2,Point q1,Point q2) { double k1=(p1.y-p2.y)/(p1.x-p2.x); double k2=(q1.y-q2.y)/(q1.x-q2.x); double b1=p1.y-k1*p1.x; double b2=q1.y-k2*q1.x; if(p1.x==p2.x && q1.x==q2.x) return p1.x==q1.x? 1:-1; if(p1.x==p2.x) { ans=Point(p1.x,k2*p1.x+b2); return 0; } if(q1.x==q2.x) { ans=Point(q1.x,k1*q1.x+b1); return 0; } if(fabs(k1-k2)<eps) return fabs(b1-b2)<eps? 1:-1; ans.x=(b2-b1)/(k1-k2); ans.y=k1*ans.x+b1; return 0; } int main() { // freopen("in.txt","r",stdin); int t; scanf("%d",&t); Point pot[4]; puts("INTERSECTING LINES OUTPUT"); while(t--) { double x,y; for(int i=0; i<4; i++) { scanf("%lf%lf",&x,&y); pot[i]=Point(x,y); } int tmp=getCross(pot[0],pot[1],pot[2],pot[3]); if(tmp==-1) puts("NONE"); else if(tmp==1) puts("LINE"); else printf("POINT %.2f %.2f\n",ans.x,ans.y); } puts("END OF OUTPUT"); return 0; }
相关文章推荐
- POJ 1269 Intersecting Lines 判断直线关系(相交(求交点),重合,平行)
- POJ 1269 判断直线和直线关系
- POJ 1269 Intersecting Lines(简单计算几何,判断直线的关系)
- poj 1269 Intersecting Lines(判断两直线关系,并求交点坐标)
- POJ 1269 Intersecting Lines(判断两直线的位置关系)
- POJ 1269 判断直线的关系:相交,平行,重合
- POJ1269:Intersecting Lines(判断两条直线的关系)
- POJ 1269 Intersecting Lines(判断两条直线的位置关系)
- POJ1269——Intersecting Lines(计算几何,直线关系判断)
- poj 1269 Intersecting Lines 【判断两条直线的关系】
- POJ 1269 直线位置关系的判断
- Intersecting Lines - POJ 1269(判断平面上两条直线的关系)
- POJ 1269 Intersecting Lines 判断直线关系(相交(求交点),重合,平行)
- 判断两条直线的位置关系 POJ 1269 Intersecting Lines
- poj 1269 Intersecting Lines (叉积 判断两直线位置关系)
- POJ 1269 直线位置关系的判断
- poj 1269 判断两直线的关系并求交点
- POJ1269 判断2条直线的位置关系
- poj 1269判断两条直线的位置关系 以及求交点
- Intersecting Lines--POJ1269(判断两条直线的关系 && 求两条直线的交点)