Intersecting Lines
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 9360   Accepted: 4210

Description

We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a plane will intersect in one of three ways: 1) no intersection because they are parallel, 2) intersect in a line because they are on top of one another (i.e. they are the same line), 3) intersect in a point. In this problem you will use your algebraic knowledge to create a program that determines how and where two lines intersect.  Your program will repeatedly read in four points that define two lines in the x-y plane and determine how and where the lines intersect. All numbers required by this problem will be reasonable, say between -1000 and 1000. 

Input

The first line contains an integer N between 1 and 10 describing how many pairs of lines are represented. The next N lines will each contain eight integers. These integers represent the coordinates of four points on the plane in the order x1y1x2y2x3y3x4y4. Thus each of these input lines represents two lines on the plane: the line through (x1,y1) and (x2,y2) and the line through (x3,y3) and (x4,y4). The point (x1,y1) is always distinct from (x2,y2). Likewise with (x3,y3) and (x4,y4).

Output

There should be N+2 lines of output. The first line of output should read INTERSECTING LINES OUTPUT. There will then be one line of output for each pair of planar lines represented by a line of input, describing how the lines intersect: none, line, or point. If the intersection is a point then your program should output the x and y coordinates of the point, correct to two decimal places. The final line of output should read "END OF OUTPUT".

Sample Input

  1. 5
  2. 0 0 4 4 0 4 4 0
  3. 5 0 7 6 1 0 2 3
  4. 5 0 7 6 3 -6 4 -3
  5. 2 0 2 27 1 5 18 5
  6. 0 3 4 0 1 2 2 5

Sample Output

  1. INTERSECTING LINES OUTPUT
  2. POINT 2.00 2.00
  3. NONE
  4. LINE
  5. POINT 2.00 5.00
  6. POINT 1.07 2.20
  7. END OF OUTPUT
  1. #include <iostream>
  2. #include <cmath>
  3. #include <cstdio>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7. struct Point{
  8. double x,y;
  9. Point(){}
  10. Point(double x,double y):x(x),y(y){}
  11. };
  12. struct Line{
  13. Point a,b;
  14. };
  15.  
  16. typedef Point Vector;
  17. Vector operator +(Vector A,Vector B){return Vector(A.x+B.x,A.y+B.y);}
  18. Vector operator -(Vector A,Vector B){return Vector(A.x-B.x,A.y-B.y);}
  19. Vector operator *(Vector A,double p){return Vector(A.x*p,A.y*p);}
  20. Vector operator /(Vector A,double p){return Vector(A.x/p,A.y/p);}
  21. bool operator < (const Point &a,const Point &b)
  22. {
  23. return a.x<b.x||(a.x==b.x&&a.y<b.y);
  24. }
  25. const double eps=1e-10;
  26.  
  27. int dcmp(double x)
  28. {
  29. if(fabs(x)<eps) return 0;
  30. else return x<0?-1:1;
  31. }
  32.  
  33. bool operator == (const Point &a,const Point &b){
  34. return (dcmp(a.x-b.x)==0 && dcmp(a.y-b.y)==0);
  35. }
  36.  
  37. double Dot(Vector A,Vector B){return A.x*B.x+A.y*B.y;}//点积
  38. double Length(Vector A){return sqrt(Dot(A,A));}//向量长度
  39. //两向量的夹角
  40. double Angle(Vector A,Vector B){return acos(Dot(A,B)/Length(A)/Length(B));}
  41.  
  42. double Cross(Vector A,Vector B){ return A.x*B.y-A.y*B.x;}//叉积
  43.  
  44. Point GetLineIntersection(Point p,Vector v,Point q,Vector w)
  45. {
  46. Vector u=p-q;
  47. double t=Cross(w,u)/Cross(v,w);
  48. return p+v*t;
  49. }
  50. double DistanceToLine(Point P,Point A,Point B)
  51. {
  52. Vector v1=B-A,v2=P-A;
  53. return fabs(Cross(v1,v2)) / Length(v1);
  54. }
  55. void judge(Line a,Line b)
  56. {
  57. Point p;
  58. if(dcmp(Cross(a.a-a.b,b.a-b.b)) == 0)
  59. {
  60. if(dcmp(DistanceToLine(b.a,a.a,a.b)) == 0)
  61. {
  62. printf("LINE\n");return ;
  63. }
  64. else
  65. {
  66. printf("NONE\n");return ;
  67. }
  68. }
  69. else
  70. {
  71. p=GetLineIntersection(a.a,a.a-a.b,b.a,b.a-b.b);
  72. printf("POINT %.2lf %.2lf\n",p.x,p.y);
  73. return ;
  74. }
  75. }
  76. int main()
  77. {
  78. int n,i;
  79. Line L1,L2;
  80. while(~scanf("%d",&n))
  81. {
  82. printf("INTERSECTING LINES OUTPUT\n");
  83. for(i=0;i < n;i++)
  84. {
  85. scanf("%lf %lf %lf %lf",&L1.a.x,&L1.a.y,&L1.b.x,&L1.b.y);
  86. scanf("%lf %lf %lf %lf",&L2.a.x,&L2.a.y,&L2.b.x,&L2.b.y);
  87. judge(L1,L2);
  88. }
  89. printf("END OF OUTPUT\n");
  90. }
  91. return 0;
  92. }

poj 1269 直线间的关系的更多相关文章

  1. POJ 1269 (直线求交)

    Problem Intersecting Lines (POJ 1269) 题目大意 给定两条直线,问两条直线是否重合,是否平行,或求出交点. 解题分析 主要用叉积做,可以避免斜率被0除的情况. 求交 ...

  2. POJ 1269 (直线相交) Intersecting Lines

    水题,以前总结的模板还是很好用的. #include <cstdio> #include <cmath> using namespace std; ; int dcmp(dou ...

  3. POJ 1269 - Intersecting Lines 直线与直线相交

    题意:    判断直线间位置关系: 相交,平行,重合 include <iostream> #include <cstdio> using namespace std; str ...

  4. 判断两条直线的位置关系 POJ 1269 Intersecting Lines

    两条直线可能有三种关系:1.共线     2.平行(不包括共线)    3.相交. 那给定两条直线怎么判断他们的位置关系呢.还是用到向量的叉积 例题:POJ 1269 题意:这道题是给定四个点p1, ...

  5. POJ 1269 Intersecting Lines (判断直线位置关系)

    题目链接:POJ 1269 Problem Description We all know that a pair of distinct points on a plane defines a li ...

  6. POJ 1269 Intersecting Lines(判断两直线位置关系)

    题目传送门:POJ 1269 Intersecting Lines Description We all know that a pair of distinct points on a plane ...

  7. poj 1269 判断直线的位置关系

    题目链接 题意 判断两条直线的位置关系,重合/平行/相交(求交点). 直线以其上两点的形式给出(点坐标为整点). 思路 写出直线的一般式方程(用\(gcd\)化为最简), 计算\(\begin{vma ...

  8. POJ 1269 /// 判断两条直线的位置关系

    题目大意: t个测试用例 每次给出一对直线的两点 判断直线的相对关系 平行输出NODE 重合输出LINE 相交输出POINT和交点坐标 1.直线平行 两向量叉积为0 2.求两直线ab与cd交点 设直线 ...

  9. 直线相交 POJ 1269

    // 直线相交 POJ 1269 // #include <bits/stdc++.h> #include <iostream> #include <cstdio> ...

随机推荐

  1. 洛谷 P2916 [USACO08NOV]为母牛欢呼Cheering up the Cows

    题目描述 Farmer John has grown so lazy that he no longer wants to continue maintaining the cow paths tha ...

  2. 技术大众化--10款无需编程的App DIY开发工具

    你有一个很棒的创意但不会编程怎么办?外包.合伙开发还是从零学编程?这里提供另外一种方式--使用无需编程的App DIY开发工具.DIY开发工具不仅节省了开发时间和资金,更为那些创意无限热爱应用的人提供 ...

  3. Mac app 破解之路

    6年之前一直做过一些内存挂,脚本挂.都是比较低级的技术. 这几年期间,断断续续利用业余时间学了一些汇编的知识,当时只是想着破解游戏. 所有的黑技术都是业余自学的,没有老师可以问,只能百度和自己领悟,比 ...

  4. softmax_loss的归一化问题

    cnn网络中,网络更新一次参数是根据loss反向传播来,这个loss是一个batch_size的图像前向传播得到的loss和除以batch_size大小得到的平均loss. softmax_loss前 ...

  5. Linux之centos7 VMware安装教程

    Linux系统安装 下面是centOS7的安装过程 VMware 系统搭建 1 新建虚拟机 2 选择自定义 3 选择稍后安装操作系统 4 选择操作系统的版本Linux centos64位 5 选择处理 ...

  6. navicat 常用快捷键

    1.ctrl+q           打开查询窗口 2.ctrl+/            注释sql语句3.ctrl+shift +/  解除注释4.ctrl+r           运行查询窗口的 ...

  7. 思维 || Make It Equal

    http://codeforces.com/contest/1065/problem/C 题意:给你n个高度分别为a[i]的塔,每次可以横着切一刀,切掉不多于k个塔,问最少切多少刀才能把塔切的都一样高 ...

  8. Web服务器☞Apache VS Nginx

    Web服务器☞Apache VS Nginx LZ最近公司有一个项目在Web服务器选型上,在Apache和Nginx之间引起了一些讨论.这两者目前都是业内优秀的web服务器,都实现了HTTP1.1协议 ...

  9. URAL1561 Winnie the Pooh

    题目描述: vjudge 题解: 高消(线性基)模$7$. 可以算是板子了. 具体见代码: #include<cstdio> #include<cstring> #includ ...

  10. 手动搭建redis集群(3台)

    安装redis 1.搜索源中的redis包 apt-cache pkgnames | grep redis 2.安装redis-server apt-get install redis-server ...