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 ...
随机推荐
- LNMP环境出现”504 gateway time-out”错误的解决方案
今天下午在调试测试VPS机器的时候,出现"504 gateway time-out"错误提示.VPS是安装的LNMP一键安装包,关于这个错误之前还没有见过,网上看到比较多的是502 ...
- mysql查询unicode字符串
mysql查询的时候会将\干掉,可以用mysql的like通配符来做like '%\u5f20\u4e09%'变成like '%_u5f20_u4e09%'
- django的model对象转化成dict
今天发现一个掉渣天的方法,Django的forms包里面有一个方法:model_to_dict(),它可以将一个model对象转化成dict. In [1]: from apps.dormitory. ...
- 解决Windows 7/win8 使用VMware虚拟机的NAT 不能上网
最近在学习linux系统,在使用debian6更新源的时候,发现Nat模式上网就是配置不了.而内外网可以ping通.所以很苦恼.最后终于解决了. 以下操作在VMware10下进行 1.首先要设置一下 ...
- 函数式C代码
代码如下: #include <stdlib.h> #include <stdio.h> typedef ]; typedef FILE* File; typedef stru ...
- [TYVJ] P1017 冗余关系
冗余关系 背景 Background 太原成成中学第3次模拟赛 第4题 描述 Description Mrs.Chen是一个很认真很称职的语文老师 ......所以,当她看到学生作文里的人物关系描 ...
- Unity3D使用NGUI做个弹窗
主要函数: NGUITools.AddChild(gameobj, prefab);//gameobj为父对象,prefab为要显示的窗体对象预制 然后写个方法,限制出现多个即可
- linux crond服务
linux crond服务 linux crond服务简介:定时执行系统命令 查看crond服务状态:[root@www ~]# /sbin/service crond status 启动.停止.重启 ...
- IC封装图片认识(二):SOP&SOJ
SOP SOP-EIAJ-TYPE-II-14L SSOP SSOP-16L TSOP(Thin Small Outline Package) TSSOP(Thin Shrink Outline Pa ...
- VCMI Mods list
http://heroescommunity.com/viewthread.php3?TID=40902 http://heroes3wog.net/ http://heroes3towns.com/ ...