题目链接: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. 通过无线网络使用ADB ( Connect to android with ADB over TCP )

    之前用USB数据线连接电脑和android手机,用adb操控手机. 后来电脑前面板的USB全坏了,键盘.鼠标.USBKkey.打印机都需USB,  少一个USB口,只得对不常用设备进行插拔切换. 于是 ...

  2. learning express step(九)

    router-level middleware works in the same way as application-level middleware, except it is bound to ...

  3. linux认识

    linux基础 根目录 文档扩展名 在Linux中,跟windows的扩展名.exe .bat.dll不同,只要在那十个字符中有x权限,这个档案就是可执行的, 但是,可被执行和执行成功是两回事,在Li ...

  4. [DK] 化学竞赛的大奖

    https://www.luogu.org/problemnew/show/T16502 无向图  缩点  树的直径  到直径两个端点的距离的较大值 #include <iostream> ...

  5. bus error(总线错误)

    转自 http://blog.csdn.net/todd911/article/details/8813321 在<C专家编程>中提到了总线错误bus error(core dumped) ...

  6. Luogu5327【ZJOI2019】语言【树上差分,线段树合并】

    题目大意 给定一棵$n$个节点的树,维护$n$个集合,一开始第$i$个集合只有节点$i$.有$m$个操作,每次操作输入一个$(u,v)$,表示将$(u,v)$这条链上所有点所属的集合合并.求有多少个无 ...

  7. mapreduce 倒序 排序 最简单 易上手

    对于mapreduce倒序只需要建立一个类,然后继承WritableComparator 在重写 Compare函数最后在main里调用一下,就可以实现倒序排序: 代码: public static ...

  8. richtextbox Ctrl+V只粘贴纯文本格式

    只能粘贴剪切板中的TXT内容 并且 不能改变 剪切板的内容1 当用户按下Ctrl+V屏蔽系统的粘贴功能,然后添加自己的功能2019年12月19日 19:34:38 private void richT ...

  9. Leetcode题目338:比特位计数(中等)

    题目描述: 给定一个非负整数 num.对于 0 ≤ i ≤ num 范围中的每个数字 i ,计算其二进制数中的 1 的数目并将它们作为数组返回. 示例 1: 输入: 2 输出: [0,1,1] 示例  ...

  10. Linux设备驱动程序 之 中断和锁

    中断和锁 1. 硬中断和软中断(包括tasklet和timer)共享数据,硬中断中使用spin_lock/spin_unlock,软中断中使用spin_lock_irq/spin_unlock_irq ...