题目传送门:POJ 1269 Intersecting Lines

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

题目大意:

  给你两条线段求这两条线段的位置关系(平行,重合,相交),若相交还要求出交点坐标

解题思路:

  判断两直线位置关系

#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#define eps 1e-6
#define sgn(x) (fabs(x) < eps ? 0 : ((x) < 0 ? -1 : 1))
using namespace std;
struct point
{
double x, y;
point(double a = , double b = ) { x = a, y = b; }
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; }
};
struct line
{
point s,e;
line(){}
line(point a,point b) { s = a;e = b; }
///判断两直线位置关系,res返回相交点坐标
pair<point,int> operator &(const line &b)const
{
point res = s;
if(sgn((s-e)^(b.s-b.e)) == )
{
if(sgn((b.s-s)^(b.e-s)) == )
return make_pair(res,);//两直线重合
else return make_pair(res,);//两直线平行
}
double t = ((s-b.s)^(b.s-b.e))/((s-e)^(b.s-b.e));
res.x += (e.x - s.x)*t;
res.y += (e.y - s.y)*t;
return make_pair(res,);//有交点
}
}; int main()
{
int T;
point ans;
line l1,l2;
scanf("%d",&T);
printf("INTERSECTING LINES OUTPUT\n");
while(T--)
{
scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&l1.s.x,&l1.s.y,
&l1.e.x,&l1.e.y,&l2.s.x,&l2.s.y,&l2.e.x,&l2.e.y);
pair<point,int> ans =l1&l2;
if( ans.second == ) printf("POINT %.2f %.2f\n",ans.first.x,ans.first.y);
else if(ans.second == ) printf("NONE\n");
else printf("LINE\n");
}
printf("END OF OUTPUT\n");
return ;
}

POJ 1269 Intersecting Lines(判断两直线位置关系)的更多相关文章

  1. poj 1269 Intersecting Lines(判断两直线关系,并求交点坐标)

    Intersecting Lines Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12421   Accepted: 55 ...

  2. POJ 1269 Intersecting Lines 判断两直线关系

    用的是初中学的方法 #include <iostream> #include <cstdio> #include <cstring> #include <al ...

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

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

  4. poj 1269 Intersecting Lines——叉积求直线交点坐标

    题目:http://poj.org/problem?id=1269 相关知识: 叉积求面积:https://www.cnblogs.com/xiexinxinlove/p/3708147.html什么 ...

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

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

  6. POJ 2398 - Toy Storage 点与直线位置关系

    Toy Storage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5439   Accepted: 3234 Descr ...

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

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

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

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

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

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

随机推荐

  1. Python--day67--Jsonresponse响应介绍和路由系统的分组命名匹配方式(简单介绍)

    1,Jsonresponse响应介绍: ,2,路由系统的分组命名匹配方式:(简单介绍)

  2. Python--day48--面向对象回顾

    面向对象回顾: 例1: 例2: 特殊方法(要背会):

  3. poj 2993

    跟poj 2996反过来了,这里比较麻烦的就是处理白棋和黑棋各棋子对应的位置 还有在最后打印棋盘式|,:,.的时候会有点繁琐(- - ACMer新手 ): 直接看代码吧: #include<cs ...

  4. java抽象类的体现-模板模式

    抽象类是多个具体子类抽象出来的父类,具有高层次的抽象性;以该抽象类作为子类的模板可以避免子类设计的随意性; 抽象类的体现主要就是模板模式设计,抽象类作为多个子类的通用模板,子类在抽象类的基础上进行拓展 ...

  5. Innodb_large_prefix

    innodb_large_prefix Prefixes, defined by the length attribute, can be up to 767 bytes long for InnoD ...

  6. git clone出现Permission denied (publickey)解决办法

    一.错误 git clone git@gitee.com:wangzaiplus/xxx.git, 出现Permission denied (publickey) 二.原因 无权限, 未将公钥添加至G ...

  7. 浅谈集合框架六——集合扩展:Arrays工具类、集合与数组相互转换方式;

    最近刚学完集合框架,想把自己的一些学习笔记与想法整理一下,所以本篇博客或许会有一些内容写的不严谨或者不正确,还请大神指出.初学者对于本篇博客只建议作为参考,欢迎留言共同学习. 之前有介绍集合框架的体系 ...

  8. spring security BCryptPasswordEncoder加密解密,不错的随机盐,不错的加密解密方法

    项目中用这个加密感觉不错啊,推荐: 1.先大体看看,了解一下 浅谈使用springsecurity中的BCryptPasswordEncoder方法对密码进行加密(encode)与密码匹配(match ...

  9. 【codeforces 789A】Anastasia and pebbles

    [题目链接]:http://codeforces.com/contest/789/problem/A [题意] 有n种物品,每种物品有wi个; 你有两个口袋,每个口袋最多装k个物品; 且口袋里面只能装 ...

  10. vue-lazyload: 想弃坑,但没有找到合适的替代品

    vue-lazyload,相信在vue项目中大家都有用到过它,同时也遇到过大大小小的坑.笔者也遇到过这样一个bug,在一个图片列表页面中,总有一定的概率图片的状态为load,导致图片一直加载中...这 ...