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

解题关键:叉积的运用。

证明:

直线的一般方程为$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. 术语-软件-软件开发:SDK(软件开发工具包)

    ylbtech-术语-软件-软件开发:SDK(软件开发工具包) 软件开发工具包(缩写:SDK.外语全称:Software Development Kit)一般都是一些软件工程师为特定的软件包.软件框架 ...

  2. Valgrind memcheck 8种错误实例

    调不尽的内存泄漏,用不完的Valgrind Valgrind 安装 1. 到www.valgrind.org下载最新版valgrind-3.2.3.tar.bz2 2. 解压安装包:tar –jxvf ...

  3. Jenkins git鬼畜集

    1. Jnekins服务重启后,莫名奇妙就报403错误,内网OK,把内网IP换成外网域名又可以. 莫名其妙解决:点了下notfiy后的Add,然后重输了一次密码,好了....但是这是新增一个账号啊!! ...

  4. MySQL 报错记录

    #--------------------------------------------------------------------------------------------------- ...

  5. Linux 命令集合-错误

    错误1 说明:在linux下,./xxx.sh执行shell脚本时会提示No such file or directory.但shell明明存在,为什么就是会提示这个呢? 这种其实是因为编码方式不对, ...

  6. 2018ICPC网络赛(焦作站)K题题解

    一.题目链接 https://nanti.jisuanke.com/t/31720 二.题意 给$N$种船只,第$i$种船的载重量是$V_i$,数量是$2^{C_i}-1$.接下来有$Q$次询问,每次 ...

  7. CGLib缺少jar出现 java.lang.ClassNotFoundException: org.objectweb.asm.Type

    CGLib实现动态代理区别于JDK动态代理,不需要目标类实现任何接口,是通过生成代理类子类的方式,而且据说速度要快于JDK动态代理.所以我想要试验一下CGlib的动态代理,网上找了些例子,自己动手写了 ...

  8. web本质

    知识内容: 1.网络协议复习 2.模拟web 3.web本质总结 参考: http://www.cnblogs.com/wupeiqi/articles/5237672.html http://www ...

  9. django项目环境设置

    1.连接数据库,如mysql DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'django_comi ...

  10. 解决 php 报错 open_basedir restriction in effect或者nginx提示No input file specified怎么办

    解决 php 报错 open_basedir restriction in effect或者nginx提示No input file specified怎么办 问题是出现在了PHP.INI上面了 ,原 ...