POJ 1269 Intersecting Lines【判断直线相交】
题意:给两条直线,判断相交,重合或者平行
思路:判断重合可以用叉积,平行用斜率,其他情况即为相交。
求交点:
这里也用到叉积的原理。假设交点为p0(x0,y0)。则有:
(p1-p0)X(p2-p0)=0
(p3-p0)X(p2-p0)=0
展开后即是
(y1-y2)x0+(x2-x1)y0+x1y2-x2y1=0
(y3-y4)x0+(x4-x3)y0+x3y4-x4y3=0
将x0,y0作为变量求解二元一次方程组。
假设有二元一次方程组
a1x+b1y+c1=0;
a2x+b2y+c2=0
那么
x=(b1*c2-b2*c1)/(a1*b2-a2*b1)
y=(a2*c1-a1*c2)/(a1*b2-a2*b1)
#include<stdio.h>
#include<string.h>
#include<math.h>
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.x+y*b.y;
}
double operator ^(const point &b)const{//叉积
return x*b.y-y*b.x;
}
}A,B,C,D;
double cal(point p0,point p1,point p2){//小于0表示在p1处左折,大于0右折,等于0同线
return (p1-p0)^(p2-p0);
}
const double eps=1e-;
int main(){
int n,i;
while(scanf("%d",&n)!=EOF){
puts("INTERSECTING LINES OUTPUT");
for(i=;i<=n;i++){
scanf("%lf%lf%lf%lf",&A.x,&A.y,&B.x,&B.y);
scanf("%lf%lf%lf%lf",&C.x,&C.y,&D.x,&D.y);
if(fabs(cal(C,A,B))<eps&&fabs(cal(D,A,B))<eps) puts("LINE");
else if((B.x-A.x)*(D.y-C.y)==(D.x-C.x)*(B.y-A.y)) puts("NONE");
else{
double a1=A.y-B.y;
double b1=B.x-A.x;
double c1=A.x*B.y-B.x*A.y;
double a2=C.y-D.y;
double b2=D.x-C.x;
double c2=C.x*D.y-D.x*C.y;
double x=(b1*c2-b2*c1)/(a1*b2-a2*b1);
double y=(a2*c1-a1*c2)/(a1*b2-a2*b1);
printf("POINT %.2f %.2f\n",x,y);
}
}
puts("END OF OUTPUT");
}
return ;
}
POJ 1269 Intersecting Lines【判断直线相交】的更多相关文章
- POJ 1269 Intersecting Lines(直线相交判断,求交点)
Intersecting Lines Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8342 Accepted: 378 ...
- POJ 1269 Intersecting Lines (判断直线位置关系)
题目链接:POJ 1269 Problem Description We all know that a pair of distinct points on a plane defines a li ...
- POJ 1269 Intersecing Lines (直线相交)
题目: Description We all know that a pair of distinct points on a plane defines a line and that a pair ...
- POJ 1269 Intersecting Lines(线段相交,水题)
id=1269" rel="nofollow">Intersecting Lines 大意:给你两条直线的坐标,推断两条直线是否共线.平行.相交.若相交.求出交点. ...
- poj 1269 Intersecting Lines(判断两直线关系,并求交点坐标)
Intersecting Lines Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12421 Accepted: 55 ...
- POJ 1269 Intersecting Lines(直线求交点)
Description We all know that a pair of distinct points on a plane defines a line and that a pair of ...
- POJ 1269 Intersecting Lines 判断两直线关系
用的是初中学的方法 #include <iostream> #include <cstdio> #include <cstring> #include <al ...
- POJ 1269 Intersecting Lines(判断两直线位置关系)
题目传送门:POJ 1269 Intersecting Lines Description We all know that a pair of distinct points on a plane ...
- poj 1269 Intersecting Lines(直线相交)
Intersecting Lines Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8637 Accepted: 391 ...
随机推荐
- 开源论坛MvcForum推荐
MvcForum算是Asp.net中开源论坛佼佼者之一.主要使用ASP.NET MVC 5 &Unity & Entity Framework 6,有较强的可撸性.是论坛开发者的不二之 ...
- Android的新虚拟机ART
- IOS6学习笔记(四)
1.GCD设置一个timer计时器 - (void)awakeFromNib { __weak id weakSelf = self; double delayInSeconds = 0.25; _t ...
- 初学Node(三)模块系统
模块系统 Node根据CommonJS规范实现了一套自己的模块机制,可以使用require()导入一个模块,使用module.exports导出一个模块. require使用 在Node中我们可以使用 ...
- REUSE_ALV_POPUP_TO_SELECT的使用技巧
通过函数的方法弹出一个对话框,提供选择数据的功能…… DATA: BEGIN OF lt_exidv OCCURS , box TYPE char1, exidv TYPE exidv, status ...
- ssh无法登录linux服务器的解决办法
最近之前使用的一台linux服务器被长官重装系统了,导致ssh登录的时候出现如下错误: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ...
- SharePoint 2013 调用WCF服务简单示例
内容比较简单,主要记录自己使用SharePoint 2013WCF服务遇到的小问题和小经验,分享给大家,希望能够给需要的人有所帮助.好吧,进入正题! 第一部分 SharePoint 2013调用自带W ...
- 根据包名字符串跳转Activity
/** * 跳转到对应activity */ public void toActivity(Context context,String fullName) { if (className != nu ...
- 【原】开发路上疑难BUG调试记录
之前遇到棘手的BUG总是在处理过后就不管了,导致后面碰到相同问题后重复工作太多.现专门开辟一篇日志以记录接下来一路上比较棘手的“坑”的修复历程: [C++篇] 1.mt.exe : general e ...
- IOS开发中NSRunloop跟NSTimer的问题
在Windows时代,大家肯定对SendMessage,PostMessage,GetMessage有所了解,这些都是windows中的消息处理函数,那对应在ios中是什么呢,其实就是NSRunloo ...