原题:

求两直线交点


思路借鉴于:http://blog.csdn.net/zxy_snow/article/details/6341282

感谢大佬

#include<cstdio>
#include<algorithm>
#include<cstring>
#define eps 1e-8
using namespace std;
int T;
struct point//点(向量的结构体)
{
double x,y;
point() {}//初始化
point (int _x,int _y) :
x(_x),y(_y) {};//用一对坐标初始化点
inline point operator + (const point &rhs) const//向量加法
{
return point(x+rhs.x,y+rhs.y);
}
inline point operator - (const point &rhs) const//向量减法
{
return point(x-rhs.x,y-rhs.y);
}
inline int operator * (const point &rhs) const//向量叉乘
//向量叉乘的几何意义是以两个向量为邻边的平行四边形的有向面积 也就是|a|*|b|*sin<a,b> 这里的sin<a,b>决定了
//如果a,b是逆时针的,那么sin<a,b>大于0,有向面积大于0,反之<0
{
return x*rhs.y-y*rhs.x;
}
friend inline int dot(const point &lhs,const point &rhs)//向量点乘
{
return lhs.x*rhs.x+lhs.y*rhs.y;
}
}p1,p2,p3,p4;
inline bool check(const point &p1,const point &p2,const point &p3)
{
if (abs((p1-p3)*(p2-p3))<eps) return 1;
return 0;
}
double abs(double x)
{
return x>0?x:-x;
}
int main()
{
scanf("%d",&T);
puts("INTERSECTING LINES OUTPUT");
while (T--)
{
scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&p1.x,&p1.y,&p2.x,&p2.y,&p3.x,&p3.y,&p4.x,&p4.y);
if (check(p1,p2,p3) && check(p1,p2,p4))
{
puts("LINE");
continue;
}
if (abs((p2.x-p1.x)*(p4.y-p3.y)-(p4.x-p3.x)*(p2.y-p1.y))<eps)
{
puts("NONE");
continue;
}
double a1=(p1.y-p2.y),b1=(p2.x-p1.x),c1=(p1.x*p2.y-p2.x*p1.y);
double a2=(p3.y-p4.y),b2=(p4.x-p3.x),c2=(p3.x*p4.y-p4.x*p3.y);
printf("POINT %.2f %.2f\n",(c1*b2-c2*b1)/(a2*b1-a1*b2),(a2*c1-a1*c2)/(a1*b2-a2*b1));
}
puts("END OF OUTPUT");
return 0;
}

ZOJ 1280 Interesting Lines | 求两直线交点的更多相关文章

  1. [poj] 1269 [zoj] 1280 Interesting Lines || 求两直线交点

    POJ原题 ZOJ原题 多组数据.每次给出四个点,前两个点确定一条直线,后两个点确定一条直线,若平行则输出"NONE",重合输出"LINE",相交输出" ...

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

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

  3. Intersecting Lines---poj1269(求两直线的位置关系)

    题目链接:http://poj.org/problem?id=1269 题意:给你两条直线上的任意不同的两点,然后求两条直线的位置关系,如果相交于一点输出该点坐标; #include<iostr ...

  4. Gym-101915B Ali and Wi-Fi 计算几何 求两圆交点

    题面 题意:给你n个圆,每个圆有一个权值,你可以选择一个点,可以获得覆盖这个点的圆中,权值最大的m个的权值,问最多权值是多少 题解:好像是叙利亚的题....我们画画图就知道,我们要找的就是圆与圆交的那 ...

  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. UVa 11178:Morley’s Theorem(两射线交点)

    Problem DMorley’s TheoremInput: Standard Input Output: Standard Output Morley’s theorem states that ...

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

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

  9. poj 1269 Intersecting Lines(判断两直线关系,并求交点坐标)

    Intersecting Lines Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12421   Accepted: 55 ...

随机推荐

  1. Redux初识

    1.定义规则counter 2.根据计算规则生成store let store=createStore(counter); 3.订阅消息(state 发生变化后发送消息) 4.触发规则,使state发 ...

  2. 1816: [Cqoi2010]扑克牌

    Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 2737  Solved: 1082[Submit][Status][Discuss] Descripti ...

  3. Python——列表

    应用场景,要统计大量的人员信息.就可以用列表的形式进行.name = ['邱秀','玄永俊','杨栋豪']查:print(name[2],name[0]) #取号码进行识别print(name[1:3 ...

  4. 使用 python快速搭建http服务

    在 Linux 服务器上或安装了 Python 的机器上,Python自带了一个WEB服务器 SimpleHTTPServer. 我们可以很简单的使用  python -m SimpleHTTPSer ...

  5. 海龟绘图turtle模块的使用

    在本章中,我们将编写简短的.简单的程序来创建漂亮的.复杂的视觉效果.为了做到这一点,我们可以使用海龟作图软件.在海龟作图中,我们可以编写指令让一个虚拟的(想象中的)海龟在屏幕上来回移动.这个海龟带着一 ...

  6. win8电脑字体出现方格的解决方法

    一般电脑出现乱码有几种可能,最常见的可能就是电脑字体的丢失,其次就是电脑字体被病毒所损坏,因此,首先我们要做的就是下载字体并进行安装. 下载 simsun.tcc点击安装,如果电脑字体依然是这种情况( ...

  7. 笔记-scrapy-extentions

    笔记-scrapy-extentions 1.      extentions 1.1.    开始 The extensions framework provides a mechanism for ...

  8. luoguP1726 上白泽慧音

    P1726 上白泽慧音 题目描述 在幻想乡,上白泽慧音是以知识渊博闻名的老师.春雪异变导致人间之里的很多道路都被大雪堵塞,使有的学生不能顺利地到达慧音所在的村庄.因此慧音决定换一个能够聚集最多人数的村 ...

  9. Hibernate SQL方言

    RDBMS 方言 DB2 org.hibernate.dialect.DB2Dialect DB2 AS/400 org.hibernate.dialect.DB2400Dialect DB2 OS3 ...

  10. An internal error occurred during: "Launching on Tomcat 7.x"

    1.首先关闭MyEclipse工作空间.2.然后删除工作空间下的文件.“MyEclipse10\workspace.metadata.plugins\org.eclipse.core.runtime. ...