Intersecting Lines

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 16681   Accepted: 7192

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

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

Source

 
两直线求交点
 //2017-08-30
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip> using namespace std; const int N = ;
const double EPS = 1e-; //三态函数
int sgn(double x){
if(fabs(x) < EPS)return ;
if(x < )return -;
else return ;
} struct Point{
double x, y;
Point(){}
Point(double _x, double _y):x(_x), y(_y){}
Point(const Point &p):x(p.x), y(p.y){}
//a-b为向量ba
Point operator- (const Point &b) const {
return Point(x-b.x, y-b.y);
}
//向量叉积
double operator^ (const Point &b) const {
return x*b.y - y*b.x;
}
//向量点积
double operator* (const Point &b) const {
return x*b.x + y*b.y;
}
}; struct Line{
Point a, b;
Line(){}
Line(Point _a, Point _b):a(_a), b(_b){}
//判断两直线关系
//input:两直线
//output:pair<int, Point> first == 0 表示直线重合
// first == 1 表示两直线平行
// first == 2 表示两直线相交,second 为交点
pair<int, Point> operator & (const Line &line) const{
Point res = a;
if(sgn((a-b)^(line.a-line.b)) == ){
if(sgn((a-line.b)^(line.a-line.b)) == )
return make_pair(, res);
else return make_pair(, res);
}
double t = ((a-line.a)^(line.a-line.b))/((a-b)^(line.a-line.b));
res.x += (b.x-a.x)*t;
res.y += (b.y-a.y)*t;
return make_pair(, res);
}
}seg[N]; int n;
int main()
{
std::ios::sync_with_stdio(false);
//freopen("inputD.txt", "r", stdin);
int T;
cin>>T;
cout<<"INTERSECTING LINES OUTPUT"<<endl;
while(T--){
Line l1, l2;
cin>>l1.a.x>>l1.a.y>>l1.b.x>>l1.b.y;
cin>>l2.a.x>>l2.a.y>>l2.b.x>>l2.b.y;
pair<int, Point> res = l1 & l2;
cout.setf(ios::fixed);
if(res.first == )
cout<<"LINE"<<endl;
else if(res.first == )
cout<<"NONE"<<endl;
else
cout<<setprecision()<<"POINT "<<res.second.x<<" "<<res.second.y<<endl;
}
cout<<"END OF OUTPUT"<<endl; return ;
}

POJ1269(KB13-D 计算几何)的更多相关文章

  1. poj1269计算几何直线和直线的关系

    We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a p ...

  2. poj1269 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 p ...

  3. 计算几何——直线交点poj1269

    求直线交点还是要推一个公式的.. 见博客https://blog.csdn.net/u013050857/article/details/40923789 还要学一下向量的定点比分法 另外poj精度好 ...

  4. ACM/ICPC 之 计算几何入门-叉积-to left test(POJ2318-POJ2398)

    POJ2318 本题需要运用to left test不断判断点处于哪个分区,并统计分区的点个数(保证点不在边界和界外),用来做叉积入门题很合适 //计算几何-叉积入门题 //Time:157Ms Me ...

  5. HDU 2202 计算几何

    最大三角形 Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  6. ACM 计算几何中的精度问题(转)

    http://www.cnblogs.com/acsmile/archive/2011/05/09/2040918.html 计算几何头疼的地方一般在于代码量大和精度问题,代码量问题只要平时注意积累模 ...

  7. hdu 2393:Higher Math(计算几何,水题)

    Higher Math Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  8. sdut 2603:Rescue The Princess(第四届山东省省赛原题,计算几何,向量旋转 + 向量交点)

    Rescue The Princess Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Several days ago, a b ...

  9. [知识点]计算几何I——基础知识与多边形面积

    // 此博文为迁移而来,写于2015年4月9日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102vxaq.html 1.前言 ...

随机推荐

  1. Javascript如何避免连续调用中取到不存在的属性而导致报TypeError错?

    背景: 在最近的 NODEJS 项目中,涉及到数据库的查询,回调函数里返回了查询结果,我这样做处理然后返回给前端: return results.collect_coupon[0].count 但是这 ...

  2. SQL 一对多联表查询最大值

    有两个数据表City表和Price表,CIty表的结构如下: Price表的结构如下: 查询每个城市最大的销售价格,并以最大价格进行降序排列,选取前5条记录,SQL语句的代码如下: * from (s ...

  3. SQLServer——SQLServer链接外部数据源

    学习链接:https://www.cnblogs.com/licin/p/6244169.html 一.新建ODBC数据源 1.打开控制面板→管理工具→ODBC数据源→系统DSN 2.添加新系统数据源 ...

  4. asp.net core中遇到需要自定义数据包解密方法的时候

    最近将公司的项目用.netcore重写, 服务的http外部接口部分收发消息是DES加解密的, 那么在asp.net core mvc的action处理之前需要加入解密这个步骤. 我第一想到的是用fi ...

  5. nc命令简介

    nc介绍 ncat/nc 既是一个端口扫描工具,也是一款安全工具,还能是一款监测工具,甚至可以做为一个简单的 TCP 代理. 在大多数 Debian 发行版中,nc 是默认可用的,它会在安装系统的过程 ...

  6. Java模式—适配器模式

    适配器模式(Adapter): 1.概念:将一个类中的接口转换为客户希望的另外一个接口,使得原本由于接口不兼容而不能一起工作的那些类可以一起工作. 2.模式中的角色 1 目标接口:客户所期待的接口.目 ...

  7. 【Canal源码分析】client工作过程

    client的工作过程,需要我们自己去编写对应的逻辑,我们目前只能从example写的例子来看.目前examle中提供了两个例子,一个是单机的,一个是集群的cluster,我们后续如果需要进行开发的话 ...

  8. android app性能优化大汇总

    这里根据网络上各位大神已经总结的知识内容做一个大汇总,作为记录,方便后续“温故知新”. 性能指标: (1)使用流畅度:  图片处理器每秒刷新的帧数(FPS),可用来指示页面是否平滑的渲染.高的帧率可以 ...

  9. ES6常用语法总结

    ECMAScript 6(以下简称ES6)是JavaScript语言的下一代标准.因为当前版本的ES6是在2015年发布的,所以又称ECMAScript 2015.也就是说,ES6就是ES2015.虽 ...

  10. HTML5本地储存sessionStorage的销毁数据问题

    前几天项目中用到了本地储存,虽然说也就是几个api,但之前有一个问题一直没有去想,我们知道本地储存分为两种,一种是临时储存,关闭浏览器后数据就会销毁,另外一种是没有时间限制的储存,我们做的这个页面比较 ...