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 ...
随机推荐
- vector -1
vector的特色有支持随机存取,在集合尾端增删元素很快,但是在集合中间增删元素比较费时. vector以模板(泛型)方式实现,可以保存任意类型的变数,包括使用者自定义的资料型态,例如:它可以是放置整 ...
- line-height下的dispay:inline-block垂直居中
html: <div class="search fl"> <span class="search-box"> <input ty ...
- [转发]Gulp开发教程(翻译)
Building With Gulp =================== 转载出处 原文地址 翻译出处 对网站资源进行优化,并使用不同浏览器测试并不是网站设计过程中最有意思的部分,但是这个过程中的 ...
- Java之集合类
出处:http://blog.csdn.net/zhangerqing 一.集合类简介 数组是很常用的一种的数据结构,我们用它可以满足很多的功能,但是,有时我们会遇到如下这样的问题: 1.我们需要该容 ...
- 使用Map/MapWhen扩展方法
使用Map/MapWhen扩展方法 .NET Core中间件的注册和管道的构建(3) ---- 使用Map/MapWhen扩展方法 0x00 为什么需要Map(MapWhen)扩展 如果业务逻辑比较简 ...
- jquery实现当前页面编辑
实现效果 代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ww ...
- 分治算法求乘方a^b 取余p(divide and conquer)
传统的计算方法为循环n个a相乘.时间复杂度为O(n). 如用分治算法,效率可提升至O(lgn). 结合recursive有 double pow(int a, int n){ ) ; ) return ...
- FP—Growth算法
FP_growth算法是韩家炜老师在2000年提出的关联分析算法,该算法和Apriori算法最大的不同有两点: 第一,不产生候选集,第二,只需要两次遍历数据库,大大提高了效率,用31646条测试记录, ...
- Linux下SVN(Subversion)自动启动脚本
在Red Hat Linux中自动运行程序 1.开机启动时自动运行程序 Linux加载后, 它将初始化硬件和设备驱动,然后运行第一个进程init.init根据配置文件继续引导过程,启动其 ...
- hdu 3339 In Action
http://acm.hdu.edu.cn/showproblem.php?pid=3339 这道题就是dijkstra+01背包,先求一遍最短路,再用01背包求. #include <cstd ...