题目大意:求两条直线的交点坐标。

解题关键:叉积的运用。

证明:

直线的一般方程为$F(x) = ax + by + c = 0$。既然我们已经知道直线的两个点,假设为$(x_0,y_0), (x_1, y_1)$,那么可以得到$a = {y_0} - {y_1}$,$b = x_1 – x_0$,$c = x_0y_1 – x_1y_0$。

因此我们可以将两条直线分别表示为

${F_0}(x) = {\rm{ }}{a_0}x{\rm{ }} + {\rm{ }}{b_0}y{\rm{ }} + {c_0} = 0,{F_1}(x) = {a_1}x + {b_1}y + {c_1} = 0$

那么两条直线的交点应该满足

${a_0}x + {b_0}y + {c_0} = {\rm{ }}{a_1}x + {b_1}y + {c_1}$

由此可推出

$\begin{array}{*{20}{l}}
{x = ({b_0}{c_1} - {b_1}{c_0})/D}\\
{y = ({a_1}{c_0} - {a_0}{c_1})/D}
\end{array}$

$D = {a_0}{b_1} - {a_1}{b_0}$ (D为0时,表示两直线平行)

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<iostream>
#define pi acos(-1)
using namespace std;
typedef long long ll;
const double eps=1e-;
const int N=,maxn=,inf=0x3f3f3f3f;
struct point{
double x,y;
};
struct line{
point a,b;
}l[N]; int main(){
int t;
double x1,x2,x3,x4,y1,y2,y3,y4;
cin>>t;
cout<<"INTERSECTING LINES OUTPUT"<<endl;
while(t--){
cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
if((x4-x3)*(y2-y1)==(y4-y3)*(x2-x1)){
if((x2-x1)*(y3-y1)==(y2-y1)*(x3-x1)) cout<<"LINE"<<endl;//用叉积判断共线
else cout<<"NONE"<<endl;
}
else{
double a1=y1-y2,b1=x2-x1,c1=x1*y2-x2*y1;//c是叉积
double a2=y3-y4,b2=x4-x3,c2=x3*y4-x4*y3;
double x=(c2*b1-c1*b2)/(b2*a1-b1*a2);
double y=(a2*c1-a1*c2)/(b2*a1-b1*a2);
printf("POINT %.2f %.2f\n",x,y);
}
}
cout<<"END OF OUTPUT"<<endl;
return ;
}

kuangbin模板。求直线的交点。(由于poj waiting,未测试)

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<iostream>
using namespace std;
typedef long long ll;
const double eps = 1e-;
int sgn(double x){
if(fabs(x)<eps)return ;
if(x<)return -;
else return ;
}
struct Point{
double x,y;
Point(){}
Point(double _x,double _y){x=_x;y=_y;}
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;}
double operator*(const Point &b)const{return x*b.x+y*b.y;}
bool operator==(const Point &b)const{return x==b.x&&y==b.y;}
};
struct Line{
Point s,e;
Line(){}
Line(Point _s,Point _e){s=_s;e=_e;}
//两直线相交求交点
pair<int,Point>operator&(const Line &b)const{
Point res=s;
if(sgn((s-e)^(b.s-b.e))==){
if(sgn((s-b.e)^(b.s-b.e))==)
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);
}
}; //*判断线段相交
bool inter(Line l1,Line l2){
return
max(l1.s.x,l1.e.x) >= min(l2.s.x,l2.e.x) &&
max(l2.s.x,l2.e.x) >= min(l1.s.x,l1.e.x) &&
max(l1.s.y,l1.e.y) >= min(l2.s.y,l2.e.y) &&
max(l2.s.y,l2.e.y) >= min(l1.s.y,l1.e.y) &&
sgn((l2.s-l1.e)^(l1.s-l1.e))*sgn((l2.e-l1.e)^(l1.s-l1.e))<= &&
sgn((l1.s-l2.e)^(l2.s-l2.e))*sgn((l1.e-l2.e)^(l2.s-l2.e))<=;
}
int main(){
int n;
printf("INTERSECTING LINES OUTPUT\n");
cin>>n;
while(n--){
int a1,b1,c1,d1,a2,b2,c2,d2;
cin>>a1>>b1>>c1>>d1>>a2>>b2>>c2>>d2;
Line a=Line(Point(a1,b1),Point(c1,d1)),b=Line(Point(a2,b2),Point(c2,d2));
pair<int,Point>pp=a&b;
if(pp.first==){
printf("LINE\n");
}else if(pp.first==){
printf("NONE\n");
}else{
Point tmp=pp.second;
printf("POINT %.2lf %.2lf\n",tmp.x,tmp.y);
}
}
printf("END OF OUTPUT\n");
}

[poj1269]Intersecting Lines的更多相关文章

  1. POJ1269:Intersecting Lines(判断两条直线的关系)

    题目:POJ1269 题意:给你两条直线的坐标,判断两条直线是否共线.平行.相交,若相交,求出交点. 思路:直线相交判断.如果相交求交点. 首先先判断是否共线,之后判断是否平行,如果都不是就直接求交点 ...

  2. POJ1269 Intersecting Lines[线段相交 交点]

    Intersecting Lines Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 15145   Accepted: 66 ...

  3. poj1269 intersecting lines【计算几何】

    We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a p ...

  4. POJ1269 Intersecting Lines 2017-04-16 19:43 50人阅读 评论(0) 收藏

    Intersecting Lines Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 15478   Accepted: 67 ...

  5. POJ1269:Intersecting Lines——题解

    http://poj.org/problem?id=1269 题目大意:给四个点,求前两个点所构成的直线和后两个点所构成的直线的位置关系(平行,重合,相交),如果是相交,输出交点坐标. ——————— ...

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

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

  7. POJ 1269 Intersecting Lines --计算几何

    题意: 二维平面,给两条线段,判断形成的直线是否重合,或是相交于一点,或是不相交. 解法: 简单几何. 重合: 叉积为0,且一条线段的一个端点到另一条直线的距离为0 不相交: 不满足重合的情况下叉积为 ...

  8. POJ 1269 Intersecting Lines【判断直线相交】

    题意:给两条直线,判断相交,重合或者平行 思路:判断重合可以用叉积,平行用斜率,其他情况即为相交. 求交点: 这里也用到叉积的原理.假设交点为p0(x0,y0).则有: (p1-p0)X(p2-p0) ...

  9. 简单几何(直线位置) POJ 1269 Intersecting Lines

    题目传送门 题意:判断两条直线的位置关系,共线或平行或相交 分析:先判断平行还是共线,最后就是相交.平行用叉积判断向量,共线的话也用叉积判断点,相交求交点 /********************* ...

随机推荐

  1. selenium操作隐藏的元素 (下拉框类型)

    有时候我们会碰到一些元素不可见,这个时候selenium就无法对这些元素进行操作了.例如,下面的情况: Python 页面主要通过“display:none”来控制整个下拉框不可见.这个时候如果直接操 ...

  2. timus1745题解

    一.题目链接 http://acm.timus.ru/problem.aspx?space=1&num=1745 二.题意 给定$n$个由'('和')'组成的字符串,每个串最多只能使用$1$次 ...

  3. labview如何生成可执行文件

    labview生成可执行文件可以分为两种情况. 第一种,是电脑中有labview软件开发环境的情况 第二种,是电脑中没有安装labview软件开发环境 下面是一个简单的labview代码: 程序解释: ...

  4. C# 获取物理网卡Mac地址

    // <summary> /// 获取网卡物理地址 /// </summary> /// <returns></returns> public stat ...

  5. 半联结&反联结!

    半联结是在两个数据集(表)之间的联结,其中第一个数据集中的数据行在决定是否返回时会根据在另一个数据集中出现或不出现至少一个相匹配的数据行来确定.“不出先”匹配行——这是半联结的一种特殊形式,称为反联结 ...

  6. python之路之装饰器

    一 装饰器进化之路1) import time def index(): start_time=time.time() time.sleep() print('welcome to index wor ...

  7. IIS7根据PID查找对应的站点

    runas /user:administrator cmd cd \Windows\System32\inetsrv appcmd.exe list wp

  8. SpringBoot整合定时任务task

    @SpringBootApplication //扫描 mybatis mapper 包路径 @MapperScan(basePackages = "com.imooc.mapper&quo ...

  9. 开源推荐系统Librec中recommender模块算法了解——cf模块

    1.      k近邻(k-NearestNeighbor)算法介绍及在推荐系统中的应用 https://zhuanlan.zhihu.com/p/25994179 k近邻(k-NearestNeig ...

  10. centos7.3下curl支持https协议

    1 由于自己的curl是默认安装的,查看了下 不支持https协议 [root@izwz90bp6do7s3cr45cw6az ~]# curl --version curl (x86_64-redh ...