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 ...
随机推荐
- org.hibernate.service.jndi.JndiException: Error parsing JNDI name []
我的hibernate.cfg.xml文件如下: <?xml version="1.0" encoding="UTF-8"?> <!DOCTY ...
- 鼠标悬停移除更换class
$("#xinl").mouseover(function() //鼠标悬停执行函数 { $(".xl").removeClass().addClass(&q ...
- cobbler之ks文件示例
#platform=x86, AMD64, or Intel EM64T #version=DEVEL # Firewall configuration,关闭防火墙 firewall --disabl ...
- Hdu1095
#include <stdio.h> int main() { int a,b; while(scanf("%d %d",&a,&b)!=EOF){ p ...
- Java学习笔记--Swing
1.创建框架 AWT中Frame类用来描述顶层窗口,在Swing中,这个类的名为JFrame,它从Frame类扩展. JFrame是少数几个在Swing不用绘制在画布上的组件之一,因此,它的修饰部件( ...
- 去掉Eclipse打开后定期弹出Usage Data Upload对话框
Eclipse 的 UDC 老定期蹦出来说要上传使用数据到 eclipse 官网服务器去除方法: 1.删除 eclipse/plugins 目录下以 org.eclipse.epp.usagedata ...
- 链接一个外部lib库的时候注意事项
1.注意这个库是Debug版还是Release版,一般windows下,约定是Debug版的库文件名会加个d. 2.注意这个库是x86还是x64版本. 3.注意生成这个lib库的是什么编译器
- HTTP常见的状态码
状态码的职责是当客户端向服务器端发送请求时,描述返回请求结果.借助状态码,用户可以知道服务器端是正常处理了请求,还是出现了什么错误.RFC2616定义的状态码,由3位数字和原因短信组成.数字中的第一位 ...
- Palindrome Linked List 解答
Question Given a singly linked list, determine if it is a palindrome. Follow up:Could you do it in O ...
- UVa156.Ananagrams
题目连接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...