POJ 1269 - Intersecting Lines 直线与直线相交
题意:
判断直线间位置关系: 相交,平行,重合
include <iostream>
#include <cstdio>
using namespace std;
struct Point
{
int x , y;
Point(int a = , int b = ) :x(a), y(b) {}
};
struct Line
{
Point s, e;
int a, b, c;//a>=0
Line() {}
Line(Point s1,Point e1) : s(s1), e(e1) {}
void Coefficient()//get a,b,c
{
a = e.y - s.y;
b = s.x - e.x;
c = e.x * s.y - s.x * e.y;
if(a < ) a = -a,b = -b,c = -c;
}
};
int Line_Inter_Line(Line & l1,Line & l2, double &x,double &y)//直线 平行: 0, 相交:1, 重合: 2
{
l1.Coefficient();
l2.Coefficient();
if(l1.a * l2.b == l2.a * l1.b)
{
if(l1.b * l2.c != l1.c * l2.b || l1.a * l2.c != l1.c * l2.a) return ;
else return ;
}
x =(double) - (l1.c * l2.b - l2.c * l1.b) / (l1.a * l2.b - l2.a * l1.b);// (c1b2-c2b1)/(a1b2-a2b1)
y =(double) (l1.c * l2.a - l2.c * l1.a) / (l1.a * l2.b - l2.a * l1.b);// (c1a2-c2a1)/(a1b2-a2b1)
return ;
}
int n;
int main()
{
puts("INTERSECTING LINES OUTPUT");
scanf("%d", &n);
while (n--)
{
Point p1, p2, p3, p4;
double x, y;
scanf("%d%d%d%d%d%d%d%d",&p1.x, &p1.y, &p2.x, &p2.y, &p3.x, &p3.y, &p4.x, &p4.y);
Line l1 = Line(p1, p2), l2 = Line(p3, p4);
int f = Line_Inter_Line(l1, l2, x, y);
if (f == ) puts("NONE");
else if (f == ) puts("LINE");
else printf("POINT %.2f %.2f\n", x, y);
}
puts("END OF OUTPUT");
}
POJ 1269 - Intersecting Lines 直线与直线相交的更多相关文章
- POJ 1269 Intersecting Lines【判断直线相交】
题意:给两条直线,判断相交,重合或者平行 思路:判断重合可以用叉积,平行用斜率,其他情况即为相交. 求交点: 这里也用到叉积的原理.假设交点为p0(x0,y0).则有: (p1-p0)X(p2-p0) ...
- poj 1269 Intersecting Lines——叉积求直线交点坐标
题目:http://poj.org/problem?id=1269 相关知识: 叉积求面积:https://www.cnblogs.com/xiexinxinlove/p/3708147.html什么 ...
- POJ 1269 Intersecting Lines(判断两直线位置关系)
题目传送门:POJ 1269 Intersecting Lines Description We all know that a pair of distinct points on a plane ...
- POJ 1269 Intersecting Lines(直线相交判断,求交点)
Intersecting Lines Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8342 Accepted: 378 ...
- poj 1269 Intersecting Lines(直线相交)
Intersecting Lines Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8637 Accepted: 391 ...
- 判断两条直线的位置关系 POJ 1269 Intersecting Lines
两条直线可能有三种关系:1.共线 2.平行(不包括共线) 3.相交. 那给定两条直线怎么判断他们的位置关系呢.还是用到向量的叉积 例题:POJ 1269 题意:这道题是给定四个点p1, ...
- POJ 1269 Intersecting Lines (判断直线位置关系)
题目链接:POJ 1269 Problem Description We all know that a pair of distinct points on a plane defines a li ...
- 简单几何(直线位置) POJ 1269 Intersecting Lines
题目传送门 题意:判断两条直线的位置关系,共线或平行或相交 分析:先判断平行还是共线,最后就是相交.平行用叉积判断向量,共线的话也用叉积判断点,相交求交点 /********************* ...
- 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 ...
随机推荐
- DTO学习系列之AutoMapper(五)----当EntityFramework爱上AutoMapper
有时候相识即是一种缘分,相爱也不需要太多的理由,一个眼神足矣,当EntityFramework遇上AutoMapper,就是如此,恋爱虽易,相处不易. 在DDD(领域驱动设计)中,使用AutoMapp ...
- (三)CodeMirror - Event
"change" (instance: CodeMirror, changeObj: object) { from, // object to, // object text, / ...
- java必备基础知识(一)
学习的一点建议: 每一门语言的学习都要从基础知识开始,学习是一个过程,"万丈高楼平地起",没有一个好的地基,想必再豪华的高楼大厦终究有一天会倒塌.因此,我们学习知识也要打牢根基,厚 ...
- 安装laravel
# 安装laravel 安装composer #安装 curl -sS https://getcomposer.org/installer | php #添加到PATH sudo mv compose ...
- B'day Gift
def main(): n = int(raw_input()) sum = 0 for i in range(n): sum += float(raw_input()) print '%.1f' % ...
- MHA环境搭建【3】node相关依赖的解决
mha的node软件包依赖于perl-DBD-Mysql 这个包,我之前有遇到过用yum安装perl-DBD-MySQL,安装完成后不能正常使用的情况,所以这里选择源码编译安装: perl5.10.1 ...
- 单片机 认识HEX文件
看过几篇常用指令的用法后,我们换换口味,介绍一下Intel 原厂所公布的HEX文件标准格式,相信经过本文的介绍,一定可以让您对8051的操作有更进一步的认识.以下是一个程序经编译器编译后所得到的HEX ...
- 阻碍android程序员发展的几个原因
1应该少看网上的android开发相关技术帖子,一个是错误很多,表达也不清楚,很多都是拷贝来拷贝去的.二个是技术变迁快,很多都过时了,经常看android技术相关帖子,养成了一种惰性,遇到问题不是去看 ...
- tyvj1297 小气的小B
描述 其实你们都不知道,小B是很小气的.一天小B带着他的弟弟小B'一起去摘果子,走着走着,他们忽然发现了一颗长满了果子的树.由于弟弟长得太矮了,弟弟只有让哥哥小B帮他摘一些果子下来.哥哥小B说:&qu ...
- bzoj1671 [Usaco2005 Dec]Knights of Ni 骑士
Description Bessie is in Camelot and has encountered a sticky situation: she needs to pass through t ...