Intersecting Lines

http://poj.org/problem?id=1269

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 18897   Accepted: 8043

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

先判断是否平行,平行的话再判断是否共线,否则把向量转换成方程,计算交点

直线的一般式方程AX+BY+C=0中,A B C分别等于:
A = Y2 - Y1
B = X1 - X2
C = X2*Y1 - X1*Y2
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#define esp 0.00000001
using namespace std; struct Vector{
double x,y;
}; struct Line{
Vector s,e;
}line[]; double Cross(Vector a,Vector b,Vector c){
return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
} int main(){
int n;
cin>>n;
Vector a,b,c,d;
double tmp;
cout<<"INTERSECTING LINES OUTPUT"<<endl;
for(int i=;i<=n;i++){
cin>>a.x>>a.y>>b.x>>b.y>>c.x>>c.y>>d.x>>d.y;
tmp=(a.x-b.x)*(c.y-d.y)-(a.y-b.y)*(c.x-d.x);
if(fabs(tmp)<esp&&fabs(Cross(a,b,d))<esp){
cout<<"LINE"<<endl;
}
else if(fabs(tmp)<esp){
cout<<"NONE"<<endl;
}
else{
double a1=a.y-b.y,b1=b.x-a.x,c1=a.x*b.y-b.x*a.y;//c是叉积
double a2=c.y-d.y,b2=d.x-c.x,c2=c.x*d.y-d.x*c.y;
double x=(c2*b1-c1*b2)/(b2*a1-b1*a2);
double y=(a2*c1-a1*c2)/(b2*a1-b1*a2);
printf("POINT %.2f %.2f\n",x,y);
}
}
cout<<"END OF OUTPUT"<<endl;
}

Intersecting Lines(叉积,方程)的更多相关文章

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

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

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

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

  3. Intersecting Lines POJ 1269

    题目大意:给出两条直线,每个直线上的两点,求这两条直线的位置关系:共线,平行,或相交,相交输出交点. 题目思路:主要在于求交点 F0(X)=a0x+b0y+c0==0; F1(X)=a1x+b1y+c ...

  4. POJ P2318 TOYS与POJ P1269 Intersecting Lines——计算几何入门题两道

    rt,计算几何入门: TOYS Calculate the number of toys that land in each bin of a partitioned toy box. Mom and ...

  5. POJ1269:Intersecting Lines(判断两条直线的关系)

    题目:POJ1269 题意:给你两条直线的坐标,判断两条直线是否共线.平行.相交,若相交,求出交点. 思路:直线相交判断.如果相交求交点. 首先先判断是否共线,之后判断是否平行,如果都不是就直接求交点 ...

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

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

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

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

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

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

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

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

随机推荐

  1. 统计numpy数组中每个值的个数

    import numpy as np from collections import Counter data = np.array([1.1,2,3,4,4,5]) Counter(data) #简 ...

  2. Android之sandbox技术

    ART 虚拟机下Hook工具:VirtualHook http://bbs.pediy.com/thread-216786.htm Github: https://github.com/rk700/V ...

  3. Chrome 鼠标左键-新标签打开

    改chrome设置 1.打开google搜索主页2.打开右下角Settings选项->Search Settings3.找到where results open选项4.把Open each se ...

  4. 给iOS开发新手送点福利,简述UIDatePicker的用法

    1.Locale 设置DatePicker的地区,即设置DatePicker显示的语言. 1.跟踪所有可用的地区,取出想要的地区 NSLog(@"%@", [NSLocale av ...

  5. reduce|sum

    reduce() 函数会对参数序列中元素进行累积. 函数将一个数据集合(链表,元组等)中的所有数据进行下列操作:用传给 reduce 中的函数 function(有两个参数)先对集合中的第 1.2 个 ...

  6. ECCV 2018 | 旷视科技提出GridFace:通过学习局部单应变换实现人脸校正

    全球计算机视觉三大顶会之一 ECCV 2018(European Conference on Computer Vision)即将于 9 月 8 -14 日在德国慕尼黑拉开帷幕,旷视科技有多篇论文被此 ...

  7. Python - Django - ORM 操作表

    ORM 的对应关系: 类        --->    数据库表对象     --->    数据库行属性     --->    字段 操作数据库表     --->     ...

  8. django-paginator

    py code... from django.core.paginator import Paginator class NewsListView(View): def get(self, reque ...

  9. 0_Simple__simpleCubemapTexture

    立方体纹理贴图 ▶ 源代码.用纹理方法把元素按原顺序从 CUDA3D 数组中取出来,求个相反数放入全局内存,输出. #include <stdio.h> #include "cu ...

  10. Some facts about topological sort

    Definition: a topological sort of a DAG G is a sort such that for all edge (i,j) in G, i precedes j. ...