poj1269 (叉积求直线的交点)
题目链接:https://vjudge.net/problem/POJ-1269
题意:给出4个顶点,表示两条直线,求这两条直线的相交情况,重合输出LINE,平行输出NONE,相交于一点输出该点的距离。
思路:
用叉积判断直线的重合和平行,并且可以用叉积求相交直线的交点。
用叉积求直线交点的模板:
double t=((a-c)^(c-d))/((a-b)^(c-d));
ans=Point(a.x+(b.x-a.x)*t,a.y+(b.y-a.y)*t)
证明见https://www.cnblogs.com/jklover/p/10484313.html。
AC code:
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std; const double eps=1e-;
int T,flag;
double x1,yy1,x2,yy2,x3,yy3,x4,yy4; struct Point{
double x,y;
Point(){}
Point(double xx,double yy):x(xx),y(yy){}
Point operator + (const Point& b)const{
return Point(x+b.x,y+b.y);
}
Point operator - (const Point& b)const{
return Point(x-b.x,y-b.y);
}
double operator * (const Point& b)const{
return x*b.x+y*b.y;
}
double operator ^ (const Point& b)const{
return x*b.y-b.x*y;
}
}ans; struct Line{
Point s,e;
Line(){};
Line(Point ss,Point ee){
s=ss,e=ee;
}
}; int sgn(double x)
{
if(abs(x) < eps)return ;
if(x < )return -;
else return ;
} void solve(){
Point a=Point(x1,yy1);
Point b=Point(x2,yy2);
Point c=Point(x3,yy3);
Point d=Point(x4,yy4);
if(sgn((b-a)^(d-c))==){
if(sgn((c-a)^(d-a))==) flag=;
else flag=;
return;
}
flag=;
double t=((a-c)^(c-d))/((a-b)^(c-d));
ans=Point(a.x+(b.x-a.x)*t,a.y+(b.y-a.y)*t);
} int main(){
scanf("%d",&T);
printf("INTERSECTING LINES OUTPUT\n");
while(T--){
scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&yy1,&x2,&yy2,&x3,&yy3,&x4,&yy4);
solve();
if(flag==) printf("LINE\n");
else if(flag==) printf("NONE\n");
else printf("POINT %.2f %.2f\n",ans.x,ans.y);
}
printf("END OF OUTPUT\n");
return ;
}
poj1269 (叉积求直线的交点)的更多相关文章
- poj 1269 Intersecting Lines——叉积求直线交点坐标
题目:http://poj.org/problem?id=1269 相关知识: 叉积求面积:https://www.cnblogs.com/xiexinxinlove/p/3708147.html什么 ...
- poj2074(求直线的交点)
题目链接:https://vjudge.net/problem/POJ-2074 题意:给定L1(Housing Line),L2(properity line),和一些L[i](obstructio ...
- hdu 2857:Mirror and Light(计算几何,点关于直线的对称点,求两线段交点坐标)
Mirror and Light Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- UVa 11437:Triangle Fun(计算几何综合应用,求直线交点,向量运算,求三角形面积)
Problem ATriangle Fun Input: Standard Input Output: Standard Output In the picture below you can see ...
- POJ_1269_Intersecting Lines_求直线交点
POJ_1269_Intersecting Lines_求直线交点 Description We all know that a pair of distinct points on a plane ...
- Uva 11178 Morley's Theorem 向量旋转+求直线交点
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=9 题意: Morlery定理是这样的:作三角形ABC每个 ...
- MATLAB—求直线或者线段之间的交点坐标
function CrossPoint( ) %% 求两条直线的交点坐标 x1 = [7.8 8]; y1 = [0.96 0.94]; %line2 x2 = [8.25 8.25]; y2 = [ ...
- 两条线段求交点+叉积求面积 poj 1408
题目链接:https://vjudge.net/problem/POJ-1408 题目是叫我们求出所有四边形里最大的那个的面积. 思路:因为这里只给了我们正方形四条边上的点,所以我们要先计算横竖线段两 ...
- C++ 根据两点式方法求直线并求两条直线的交点
Line.h #pragma once //Microsoft Visual Studio 2015 Enterprise //根据两点式方法求直线,并求两条直线的交点 #include"B ...
随机推荐
- 团队开发前端VUE项目代码规范
团队开发前端VUE项目代码规范 2018年09月22日 20:18:11 我的小英短 阅读数 1658 一.规范目的: 统一编码风格,命名规范,注释要求,在团队协作中输出可读性强,易维护,风格一致 ...
- 03_每周 5 使用 tar 命令备份/var/log 下的所有日志文件
]# vim /root/logbak.shtar -czf log-`date +%Y%m%d`.tar.gz /var/log ]# crontab -e -u root00 03 * * 5 / ...
- SP1716 GSS3(线段树+矩阵乘法)
Code: #include <bits/stdc++.h> #define N 50001 #define ll long long #define lson now<<1 ...
- 推荐 | Vue 入门&进阶路线
今儿跟大家聊聊 Vue . 不得不承认, Vue 越来越受欢迎了.对比 Angular 和 React,虽然三者都是非常优秀的前端框架,但从 GitHub 趋势看,Vue 已经排在第一位,达到了13万 ...
- python3实现互信息和左右熵的新词发现--基于字典树
字典树 原来讲明白了剩下的就是具体实现了,最适合存储和计算词频的数据结构就是字典树,这里给一个讲解的很清楚的链接 具体代码 代码已开源,需要的点击这个Github
- confluence乱码问题
1.上传附件需要统一字体,以测试通过:宋体字.雅黑.黑体 2.系统已做编码优化,支持windows字体.如下: 点击查看 3.之前文件有乱码,请重新上传 4.编辑一个 Office 附件文档的要求 当 ...
- 内存管理1 retain & release
内存管理法则 1:谁创建谁释放alloc /new/ copy------>release/autorelease.一一对应,不是你创建的就不用你释放. 2:除了alloc /new/ copy ...
- 微信小程序之简单记账本开发记录(四)
昨天搭建了大致界面 今天需要将用到的一系列样式表配置出来并检查错误
- HTTP header 介绍 转载
这篇文章为大家介绍了HTTP头部信息,中英文对比分析,还是比较全面的,若大家在使用过程中遇到不了解的,可以适当参考下 HTTP 头部解释 1. Accept:告诉WEB服务器自己接受什么介质类型,*/ ...
- UVALive 3716 DNA Regions ——(扫描法)
乍一看这个问题似乎是很复杂,但其实很好解决. 先处理出每个点到原点的距离和到x正半轴的角度(从x正半轴逆时针旋转的角度).然后以后者进行排序. 枚举每一个点到圆心的距离,作为半径,并找出其他到圆心距离 ...