题目链接: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 (叉积求直线的交点)的更多相关文章

  1. poj 1269 Intersecting Lines——叉积求直线交点坐标

    题目:http://poj.org/problem?id=1269 相关知识: 叉积求面积:https://www.cnblogs.com/xiexinxinlove/p/3708147.html什么 ...

  2. poj2074(求直线的交点)

    题目链接:https://vjudge.net/problem/POJ-2074 题意:给定L1(Housing Line),L2(properity line),和一些L[i](obstructio ...

  3. hdu 2857:Mirror and Light(计算几何,点关于直线的对称点,求两线段交点坐标)

    Mirror and Light Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  4. UVa 11437:Triangle Fun(计算几何综合应用,求直线交点,向量运算,求三角形面积)

    Problem ATriangle Fun Input: Standard Input Output: Standard Output In the picture below you can see ...

  5. POJ_1269_Intersecting Lines_求直线交点

    POJ_1269_Intersecting Lines_求直线交点 Description We all know that a pair of distinct points on a plane ...

  6. Uva 11178 Morley's Theorem 向量旋转+求直线交点

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=9 题意: Morlery定理是这样的:作三角形ABC每个 ...

  7. MATLAB—求直线或者线段之间的交点坐标

    function CrossPoint( ) %% 求两条直线的交点坐标 x1 = [7.8 8]; y1 = [0.96 0.94]; %line2 x2 = [8.25 8.25]; y2 = [ ...

  8. 两条线段求交点+叉积求面积 poj 1408

    题目链接:https://vjudge.net/problem/POJ-1408 题目是叫我们求出所有四边形里最大的那个的面积. 思路:因为这里只给了我们正方形四条边上的点,所以我们要先计算横竖线段两 ...

  9. C++ 根据两点式方法求直线并求两条直线的交点

    Line.h #pragma once //Microsoft Visual Studio 2015 Enterprise //根据两点式方法求直线,并求两条直线的交点 #include"B ...

随机推荐

  1. Flask-第三方插件

    Flask-Session 因为flask自带的session是将session存在cookie中: 所以才有了第三方Flask_session插件,可以将session存储在我们想存储的数据库中(r ...

  2. ubuntu 14.04 安装ntp

    安装 sudo apt-get install ntp 修改ntp.conf配置文件 sudo vi /etc/ntp.conf 修改为如下内容 # Enable this if you want s ...

  3. Ubuntu14.04 支持 exFat 格式操作

    推荐u盘使用exfat格式,为什么呢?两个原因: 1.三大主流操作系统(Linux.Mac.Windows)都支持exfat格式.2.exfat支持大于4G的文件. 在ubuntu下,由于版权的原因( ...

  4. vue 使用 echart ,自定义样式案例

    1.vue 安装 echart 库 npm install echarts --save 2.vue代码 引入 let echarts = require("echarts/lib/echa ...

  5. CF1208A

    CF1208A 题意: 就是把斐波那契数列的+改成异或,求第n项的值. 解法: 又是一个人类智慧题,打表找规律. 可以发现答案在 $ a,b,a⊕b $ 三个数中循环 CODE: #include&l ...

  6. 表单 Flask-WTF - 使用

    1 配置 可以使用Flask-WTF来处理web表单,在使用之前要先配置下,打开config.py,编辑添加如下内容 WTF_CSRF_ENABLED = True SECRET_KEY = 'you ...

  7. ajax与HTML5 history API实现无刷新跳转

    一.ajax载入与浏览器历史的前进与后退 ajax可以实现页面的无刷新操作,但是无法前进与后退,淡出使用Ajax不利于SEO.如今,HTML5让事情变得简单.当执行ajax操作时,往浏览器histor ...

  8. Nginx 出现 403 Forbidden 最终解决方法

    Nginx 出现 403 Forbidden 最终解决 步骤一: 检查目录权限.权限不足的就加个权限吧. 例子:chmod -R 755 / var/www 步骤二: 打开nginx.conf 例子: ...

  9. I am a legend: Hacking Hearthstone with machine-learning Defcon talk wrap-up

    I am a legend: Hacking Hearthstone with machine-learning Defcon talk wrap-up: video and slides avail ...

  10. UML期末复习题——2.2:UML Activity Diagram.

    第二题:活动图 重要概念: 活动图:一种有助于使工作流和业务过程可视化的图. 绘制要点: 具体方法见:http://www.cnblogs.com/xiaolongbao-lzh/p/4591953. ...