POJ 1269 Intersecting Lines(判断两直线位置关系)
题目传送门:POJ 1269 Intersecting Lines
Description
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
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
题目大意:
给你两条线段求这两条线段的位置关系(平行,重合,相交),若相交还要求出交点坐标
解题思路:
判断两直线位置关系
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#define eps 1e-6
#define sgn(x) (fabs(x) < eps ? 0 : ((x) < 0 ? -1 : 1))
using namespace std;
struct point
{
double x, y;
point(double a = , double b = ) { x = a, y = b; }
point operator-(const point& b) const { return point(x - b.x, y - b.y); }
double operator^(const point& b) const { return x * b.y - y * b.x; }
};
struct line
{
point s,e;
line(){}
line(point a,point b) { s = a;e = b; }
///判断两直线位置关系,res返回相交点坐标
pair<point,int> operator &(const line &b)const
{
point res = s;
if(sgn((s-e)^(b.s-b.e)) == )
{
if(sgn((b.s-s)^(b.e-s)) == )
return make_pair(res,);//两直线重合
else return make_pair(res,);//两直线平行
}
double t = ((s-b.s)^(b.s-b.e))/((s-e)^(b.s-b.e));
res.x += (e.x - s.x)*t;
res.y += (e.y - s.y)*t;
return make_pair(res,);//有交点
}
}; int main()
{
int T;
point ans;
line l1,l2;
scanf("%d",&T);
printf("INTERSECTING LINES OUTPUT\n");
while(T--)
{
scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&l1.s.x,&l1.s.y,
&l1.e.x,&l1.e.y,&l2.s.x,&l2.s.y,&l2.e.x,&l2.e.y);
pair<point,int> ans =l1&l2;
if( ans.second == ) printf("POINT %.2f %.2f\n",ans.first.x,ans.first.y);
else if(ans.second == ) printf("NONE\n");
else printf("LINE\n");
}
printf("END OF OUTPUT\n");
return ;
}
POJ 1269 Intersecting Lines(判断两直线位置关系)的更多相关文章
- poj 1269 Intersecting Lines(判断两直线关系,并求交点坐标)
Intersecting Lines Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12421 Accepted: 55 ...
- POJ 1269 Intersecting Lines 判断两直线关系
用的是初中学的方法 #include <iostream> #include <cstdio> #include <cstring> #include <al ...
- 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——叉积求直线交点坐标
题目:http://poj.org/problem?id=1269 相关知识: 叉积求面积:https://www.cnblogs.com/xiexinxinlove/p/3708147.html什么 ...
- 判断两条直线的位置关系 POJ 1269 Intersecting Lines
两条直线可能有三种关系:1.共线 2.平行(不包括共线) 3.相交. 那给定两条直线怎么判断他们的位置关系呢.还是用到向量的叉积 例题:POJ 1269 题意:这道题是给定四个点p1, ...
- POJ 2398 - Toy Storage 点与直线位置关系
Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5439 Accepted: 3234 Descr ...
- 简单几何(直线位置) POJ 1269 Intersecting Lines
题目传送门 题意:判断两条直线的位置关系,共线或平行或相交 分析:先判断平行还是共线,最后就是相交.平行用叉积判断向量,共线的话也用叉积判断点,相交求交点 /********************* ...
- POJ 1269 Intersecting Lines【判断直线相交】
题意:给两条直线,判断相交,重合或者平行 思路:判断重合可以用叉积,平行用斜率,其他情况即为相交. 求交点: 这里也用到叉积的原理.假设交点为p0(x0,y0).则有: (p1-p0)X(p2-p0) ...
- POJ 1269 Intersecting Lines(直线相交判断,求交点)
Intersecting Lines Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8342 Accepted: 378 ...
随机推荐
- pycharm解析器找不到
pycharm每个项目都需要设定解释器位置吧,把自己解释器位置添加到项目设置就好了 先装python,再装pycharm,不然找不到解析器的,解析器其实就是python.exe.
- nginx服务器究竟是怎么执行php项目
https://jingyan.baidu.com/article/4f34706e3af779e387b56dc7.html CGI全称是“公共网关接口”(Common Gateway Interf ...
- Vue 双向数据绑定v-model
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- java 打印流
(只有两个,PrintWriter和PrintStream) 思考:如果现在要想完成一个字符串或者是boolean型或者是字符型的数据输出使用OutputStream是否方便? 肯定是不方便的,因为O ...
- 乐视X3-40S智能电视的简化系统刷机
步骤 USB2.0-U盘一个. 先把letv原厂包里的.bin文件放入U盘刷入电视 (U盘插在电视上方的USB2.0插口处,在电视待机状态下用遥控器依次按下[3].[6].[9].[5].[开机]键, ...
- CSS选择器权重计算规则
从CSS代码存放位置看权重优先级:内嵌样式 > 内部样式表 > 外联样式表.其实这个基本可以忽视之,大部分情况下CSS代码都是使用外联样式表. 从样式选择器看权重优先级:important ...
- vue-learning:0 - 目录
Vue-learning vue.js学习路径 Vue的API地图 点击查看vue的API地图 视图层 点击可直接到达详情页面 指令 {{ }} / v-html v-if / v-else / v- ...
- 面试题 —— Ajax的基本原理总结
Ajax 的全称是Asynchronous JavaScript and XML(异步的JavaScript 和 XML),其中,Asynchronous 是 异步 的意思,它有别于传统web开发中采 ...
- Android利用Fiddler进行网络数据抓包,手机抓包工具汇总,使用mono运行filddler
Fiddler抓包工具 Fiddler抓包工具很好用的,它可以干嘛用呢,举个简单例子,当你浏览网页时,网页中有段视频非常好,但网站又不提供下载,用迅雷下载你又找不到下载地址,这个时候,Fiddler抓 ...
- Python12_关于文件概念的讨论与序列化
文件是什么? 存储在一些设备上的信息的集合.一堆字节: ====================================================到底什么是二进制文件.和文本文件,它们有 ...