Intersecting Lines

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

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

Sample Output

INTERSECTING LINES OUTPUT
POINT 2.00 2.00
NONE
LINE
POINT 2.00 5.00
POINT 1.07 2.20
END OF OUTPUT

题目大意,求给定两条线段的位置关系。

这是计算几何的基本操作,也没什么好说的吧(=o=),直接上板。

 #include<cmath>
 #include<cstring>
 #include<cstdio>
 #include<algorithm>
 #define Vec point
 using namespace std;
 ;
 int n;
 struct point{
     double x,y;
     void read(){scanf("%lf%lf",&x,&y);}
     void write(){printf("POINT %.2lf %.2lf\n",x,y);}
 }seg1a,seg1b,seg2a,seg2b,ans;
 :x>eps;}
 Vec operator + (point u,Vec v){
     Vec ret; ret.x=u.x+v.x,ret.y=u.y+v.y;
     return ret;
 }
 Vec operator - (point u,point v){
     Vec ret; ret.x=u.x-v.x,ret.y=u.y-v.y;
     return ret;
 }
 Vec operator * (Vec u,double v){
     Vec ret; ret.x=u.x*v,ret.y=u.y*v;
     return ret;
 }
 Vec operator / (Vec u,double v){
     Vec ret; ret.x=u.x/v,ret.y=u.y/v;
     return ret;
 }
 double cross(Vec u,Vec v){return u.x*v.y-u.y*v.x;}
 struct line{
     double A,B,C;
 }seg1,seg2;
 line maker(point u,point v){
     line ret;
     ret.A=v.y-u.y;
     ret.B=u.x-v.x;
     ret.C=v.x*u.y-u.x*v.y;
     return ret;
 }
 int intersect(line u,line v,point &ret){
     ){
         &&fabso(u.C*v.B-v.C*u.B)==;
     }
     ret.x=(u.B*v.C-v.B*u.C)/(u.A*v.B-v.A*u.B);
     ret.y=(v.A*u.C-u.A*v.C)/(u.A*v.B-v.A*u.B);
     ;
 }
 int main(){
     scanf("%d",&n);
     puts("INTERSECTING LINES OUTPUT");
     ; i<=n; i++){
         seg1a.read(),seg1b.read(),seg2a.read(),seg2b.read();
         seg1=maker(seg1a,seg1b);
         seg2=maker(seg2a,seg2b);
         ) puts("LINE");else
         ) puts("NONE");else
         ans.write();
     }
     puts("END OF OUTPUT");
     ;
 } 

Intersecting Lines的更多相关文章

  1. POJ 1269 Intersecting Lines --计算几何

    题意: 二维平面,给两条线段,判断形成的直线是否重合,或是相交于一点,或是不相交. 解法: 简单几何. 重合: 叉积为0,且一条线段的一个端点到另一条直线的距离为0 不相交: 不满足重合的情况下叉积为 ...

  2. POJ 1269 Intersecting Lines【判断直线相交】

    题意:给两条直线,判断相交,重合或者平行 思路:判断重合可以用叉积,平行用斜率,其他情况即为相交. 求交点: 这里也用到叉积的原理.假设交点为p0(x0,y0).则有: (p1-p0)X(p2-p0) ...

  3. 简单几何(直线位置) POJ 1269 Intersecting Lines

    题目传送门 题意:判断两条直线的位置关系,共线或平行或相交 分析:先判断平行还是共线,最后就是相交.平行用叉积判断向量,共线的话也用叉积判断点,相交求交点 /********************* ...

  4. 【POJ】1269 Intersecting Lines(计算几何基础)

    http://poj.org/problem?id=1269 我会说这种水题我手推公式+码代码用了1.5h? 还好新的一年里1A了---- #include <cstdio> #inclu ...

  5. POJ 1269 Intersecting Lines(计算几何)

    题意:给定4个点的坐标,前2个点是一条线,后2个点是另一条线,求这两条线的关系,如果相交,就输出交点. 题解:先判断是否共线,我用的是叉积的性质,用了2遍就可以判断4个点是否共线了,在用斜率判断是否平 ...

  6. poj 1269 Intersecting Lines

    题目链接:http://poj.org/problem?id=1269 题目大意:给出四个点的坐标x1,y1,x2,y2,x3,y3,x4,y4,前两个形成一条直线,后两个坐标形成一条直线.然后问你是 ...

  7. POJ 1269 Intersecting Lines(直线相交判断,求交点)

    Intersecting Lines Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8342   Accepted: 378 ...

  8. POJ 1269 Intersecting Lines(几何)

    题目链接 题意 : 给你两条线段的起点和终点,一共四个点,让你求交点坐标,如果这四个点是共线的,输出“LINE”,如果是平行的就输出“NONE”. 思路 : 照着ZN留下的模板果然好用,直接套上模板了 ...

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

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

  10. Intersecting Lines - POJ 1269(判断平面上两条直线的关系)

    分析:有三种关系,共线,平行,还有相交,共线和平行都可以使用叉积来进行判断(其实和斜率一样),相交需要解方程....在纸上比划比划就出来了....   代码如下: ================== ...

随机推荐

  1. 2、zabbix工作原理及安装配置

      Zabbix架构:zabbix基本术语.zabbix安装.配置和应用 Zabbix架构中的组件: zabbix-server:C语言    zabbix-server和zabbix-agent通过 ...

  2. 【BZOJ】1831: [AHOI2008]逆序对

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1831 考虑$-1$的位置上填写的数字一定是不降的. 令${f[i][j]}$表示$DP$到 ...

  3. ppython的移位操作

    因为要将js的一个签名算法移植到python上,遇到一些麻烦. int无限宽度,不会溢出 算法中需要用到了32位int的溢出来参与运算,但是python的int是不会溢出的,达到界限后会自己转为lon ...

  4. 使用openpyxl实现excel文件的读取操作

    1.环境准备 python3环境.安装openpyxl模块 2.excel文件数据准备 3.为方便直接调用,本代码直接封装成类 from openpyxl import load_workbook c ...

  5. Vscode中运行js文件或部分代码 ,在下面cmd输出中显示结果

    重启 vscode,  这个插件  真好用,, 赞个 ....

  6. 大数据 - spark-sql 常用命令

    --spark启动 spark-sql --退出 spark-sql> quit; --退出spark-sql or spark-sql> exit; 1.查看已有的database sh ...

  7. js正则表达式的积累

    验证数字:^[0-9]*$ 验证n位的数字:^\d{n}$ 验证至少n位数字:^\d{n,}$ 验证m-n位的数字:^\d{m,n}$ 验证零和非零开头的数字:^(0|[1-9][0-9]*)$ 验证 ...

  8. PyMongo官方文档翻译——VNPY

    PyMongo是MongoDB数据库的python模块 VNPY默认的数据库,没有采用SQL类型的数据库,而是采用No-Sql类型的MongoDB数据库, 对于想了解VNPY内部结构的童鞋,多多少少会 ...

  9. ubuntu16.04安装nvidia ,cuda(待完善)

    ubuntu16.04安装nvidia 1.首先查看自己的pc显卡的型号 ubuntu16.04 查看方法: 查看GPU型号 :lspci | grep -i nvidia 查看NVIDIA驱动版本: ...

  10. 第十二周(MySort)

    注意:研究sort的其他功能,要能改的动代码,需要答辩 模拟实现Linux下Sort -t : -k 2的功能. 要有伪代码,产品代码,测试代码(注意测试用例的设计) 参考 Sort的实现.提交博客链 ...