poj 1269 计算几何
/**
判断直线位置关系
**/
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
struct point {
double x,y;
point(double x=,double y=):x(x),y(y){}
}; typedef point Vector; Vector operator - (point A,point B){
return Vector(A.x-B.x,A.y-B.y);
} struct line {
point a,b;
};
double length(Vector v){
return sqrt(v.x*v.x+v.y*v.y);
} double cross(Vector A,Vector B){
return A.x*B.y-A.y*B.x;
} double distoline(point P,point A,point B){
Vector v1 =B-A,v2 = P-A;
return fabs(cross(v1,v2))/length(v1);
} int main()
{
int n;
cin>>n;
line l1,l2;
cout<<"INTERSECTING LINES OUTPUT"<<endl;
while(n--){
cin>>l1.a.x>>l1.a.y>>l1.b.x>>l1.b.y;
cin>>l2.a.x>>l2.a.y>>l2.b.x>>l2.b.y;
Vector tmp1,tmp2;
tmp1.x = l1.b.x-l1.a.x;
tmp1.y = l1.b.y-l1.a.y;
tmp2.x = l2.b.x-l2.a.x;
tmp2.y = l2.b.y-l2.a.y;
//cout<<tmp1.x<<" "<<tmp1.y<<endl;
//cout<<tmp2.x<<" "<<tmp2.y<<endl;
//cout<<cross(tmp1,tmp2)<<endl;
if(cross(tmp1,tmp2)==){
if(distoline(l1.a,l2.a,l2.b)==){
cout<<"LINE"<<endl;
}else
cout<<"NONE"<<endl;
}else{
double x,y;
if(l1.a.x==l1.b.x&&l2.a.x!=l2.b.x){
x = l1.a.x;
double k = (l2.b.y-l2.a.y)/(l2.b.x-l2.a.x);
double b = l2.a.y-k*l2.a.x;;
y = k*x+b;
}else if(l1.a.x!=l1.b.x&&l2.a.x==l2.b.x){
x = l2.a.x;
double k = (l1.b.y-l1.a.y)/(l1.b.x-l1.a.x);
double b = l1.a.y-k*l1.a.x;
y = k*x+b;
}else{
double k1= (l1.b.y-l1.a.y)/(l1.b.x-l1.a.x);
double b1=l1.a.y-k1*l1.a.x;
double k2 = (l2.b.y-l2.a.y)/(l2.b.x-l2.a.x);
double b2=l2.a.y-k2*l2.a.x;
x =(b2-b1)/(k1-k2);
y = k1*x+b1;
} printf("POINT %.2lf %.2lf\n",x,y);
}
}
cout<<"END OF OUTPUT"<<endl;
return ;
}
poj 1269 计算几何的更多相关文章
- POJ 1269 (直线求交)
Problem Intersecting Lines (POJ 1269) 题目大意 给定两条直线,问两条直线是否重合,是否平行,或求出交点. 解题分析 主要用叉积做,可以避免斜率被0除的情况. 求交 ...
- 直线相交 POJ 1269
// 直线相交 POJ 1269 // #include <bits/stdc++.h> #include <iostream> #include <cstdio> ...
- 判断两条直线的位置关系 POJ 1269 Intersecting Lines
两条直线可能有三种关系:1.共线 2.平行(不包括共线) 3.相交. 那给定两条直线怎么判断他们的位置关系呢.还是用到向量的叉积 例题:POJ 1269 题意:这道题是给定四个点p1, ...
- poj 1269 线段与线段相交
Intersecting Lines Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13605 Accepted: 60 ...
- 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 Intersecting Lines(判断两直线位置关系)
题目传送门:POJ 1269 Intersecting Lines Description We all know that a pair of distinct points on a plane ...
- POJ 1269 Intersecting Lines --计算几何
题意: 二维平面,给两条线段,判断形成的直线是否重合,或是相交于一点,或是不相交. 解法: 简单几何. 重合: 叉积为0,且一条线段的一个端点到另一条直线的距离为0 不相交: 不满足重合的情况下叉积为 ...
- POJ 1269 Intersecting Lines(计算几何)
题意:给定4个点的坐标,前2个点是一条线,后2个点是另一条线,求这两条线的关系,如果相交,就输出交点. 题解:先判断是否共线,我用的是叉积的性质,用了2遍就可以判断4个点是否共线了,在用斜率判断是否平 ...
- ●POJ 1269 Intersecting Lines
题链: http://poj.org/problem?id=1269 题解: 计算几何,直线交点 模板题,试了一下直线的向量参数方程求交点的方法. (方法详见<算法竞赛入门经典——训练指南> ...
随机推荐
- Tcl学习之--语法|变量
[语法|变量] l 脚本.命令和单词 Tcl提供了大约100条命令.Tk提供了另外几十条,脚本包括一条或多条,通过换行符或分号分隔开. set a 12 set b 23 也能够写成一行: set a ...
- hdu - 1757 - A Simple Math Problem
题意:当x < 10时, f(x) = x: 当x >= 10 时,f(x) = a0 * f(x-1) + a1 * f(x-2) + + a2 * f(x-3) + …… + a9 ...
- 大型票务系统中username和password的安全性问题
讨论请移步至:http://www.zhiliaotech.com/ideajam/idea/detail/307 相关文章: <今天你买到票了吗?--从铁道部12306.cn站点漫谈电子商务站 ...
- 使用window.postMessage实现跨域通信
JavaScript由于同源策略的限制,跨域通信一直是棘手的问题.当然解决方案也有很多: document.domain+iframe的设置,应用于主域相同而子域不同: 利用iframe和locati ...
- C# 想要程序文件移动 而数据保持相对位置
如果用的数据库是access数据库 可以把数据库文件放到bin\debug下面,引用相对位置就可以了 如果程序中有上载文件,而程序需要使用到该文件,那么我们最好也是引用相对文件,我们只需要在数据表中的 ...
- android入门——UI(1)
一.使用TextView ImageView Button EditView做出登录页面 <?xml version="1.0" encoding="utf-8&q ...
- C# 创建文件时,文件夹不存在,如何自动创建文件夹
c# 创建文件时怎么创建文件夹?strhtml=......StreamWriter sw=new StreamWriter("D:/test/1.aspx",false);sw. ...
- C++ try catch 捕获空指针异常,数组越界异常
#include <exception> #include <iostream> using namespace std; /************************* ...
- Linux学习之输入输出重定向
转自:http://www.cnblogs.com/chengmo/archive/2010/10/20/1855805.html 多谢分享 在了解重定向之前,我们先来看看linux 的文件描述符. ...
- tag标签添加删除并把值存入到一个input的value内
html: <input type="text" id="tagValue" style="display: none;" /> ...