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. 术语-服务:BaaS

    ylbtech-术语-服务:BaaS BaaS(后端即服务:Backend as a Service)公司为移动应用开发者提供整合云后端的边界服务. 1.返回顶部 1. 中文名:后端即服务 外文名:B ...

  2. Unreal Engine 4 笔记

    1.UE4的调试输出 //*1 调试输出*// /*case a.快速使用 不设置log类别 默认为LogTemp*/ UE_LOG(LogTemp,Log,TEXT("Your messa ...

  3. Oracle函数中将参数放在模糊查询中

    --diagnosis_name like '%'||diagnosis_names||'%' create or replace function asdf(MIN_DATE IN varchar2 ...

  4. javascript的焦点管理

    HTML5也添加了辅助管理DOM焦点的功能. 元素获得焦点的方式有页面加载,用户输入和代码中调用的focus()方法. 而document.activeElement属性保存着当前获得焦点的引用. v ...

  5. sqoop操作之HDFS导出到ORACLE

    注意:在导出前需要先创建待导出的表结构.如果导出的表在数据库中不存在则会报错:如果重复导出多次,表中的数据会重复: ; ; 导出表的所有字段 sqoop export --connect jdbc:o ...

  6. PHP MySQL Order By

    ORDER BY 关键词用于对记录集中的数据进行排序. ORDER BY 关键词 ORDER BY 关键词用于对记录集中的数据进行排序. ORDER BY 关键词默认对记录进行升序排序. 如果你想降序 ...

  7. 深度学习、图像识别入门,从VGG16卷积神经网络开始

    刚开始接触深度学习.卷积神经网络的时候非常懵逼,不知道从何入手,我觉得应该有一个进阶的过程,也就是说,理应有一些基本概念作为奠基石,让你有底气去完全理解一个庞大的卷积神经网络: 本文思路: 一.我认为 ...

  8. linux移动复制删除命令

    用mv命令1.作用mv命令来为文件或目录改名或将文件由一个目录移入另一个目录中.该命令等同于DOS系统下的ren和move命令的组合.它的使用权限是所有用户.2.格式mv [options] 源文件或 ...

  9. mac mysql中文乱码问题

    God,今天看了好多资料,除了让我命令更熟练以外浪费了好多时间. 遇到的问题:写入数据库有中文的时候,显示??? 最后解决办法: 1.打开终端,输入: mysql -u root -p,然后输入mys ...

  10. 常用数据库4 mongodb

    知识内容: 1.mongodb介绍与基本使用 2.mongodb操作 一.mongodb介绍与基本使用 1.mongodb介绍 Mongodb是一款强大,灵活,且易于扩展的通用型数据库.它能扩展出非常 ...