POJ 1269 Intersecting Lines(计算几何 求交点)
来源:互联网 发布:扬尘检测仪规定数据 编辑:程序博客网 时间:2024/05/18 21:06
题意: 求共线,平行或交点
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <queue>using namespace std;const double EPS = 1e-6;const double INF = 1e20;bool zero(double a){return -EPS<a&&a<EPS;}struct cvector{ double x,y; cvector(double a,double b){x=a,y=b;} cvector(){}};cvector operator+(cvector a,cvector b){ return cvector(a.x+b.x,a.y+b.y);}cvector operator-(cvector a,cvector b){ return cvector(a.x-b.x,a.y-b.y);}double operator*(cvector a,cvector b){ return a.x*b.x+a.y*b.y;}cvector operator*(double a,cvector b){ return cvector(a*b.x,a*b.y);}double operator^(cvector a,cvector b){ return a.x*b.y-b.x*a.y;}double length(double t){return t>0?t:-t;}double length(cvector a){return sqrt(a*a);}struct cpoint{ double x,y; cpoint(double a,double b){x=a,y=b;} cpoint(){}};cvector operator-(cpoint a,cpoint b){ return cvector(b.x-a.x,b.y-a.y);}double dist(cpoint a,cpoint b){ return length(b-a);}struct cline{ cpoint a,b;} l1,l2;bool parallel(cline a,cline b){ return zero((a.a-a.b)^(b.a-b.b));}double dist(cpoint a,cline b){ return length((a-b.a)^(b.b-b.a))/length(b.b-b.a);}cpoint intersect(cline a,cline b){ double x,y; y=((b.a.x-a.a.x)*(a.b.y-a.a.y)*(b.b.y-b.a.y)+(a.b.x-a.a.x)*(b.b.y-b.a.y)*a.a.y-(a.b.y-a.a.y)*(b.b.x-b.a.x)*b.a.y)/((a.b-a.a)^(b.b-b.a)); x=((b.a.y-a.a.y)*(a.b.x-a.a.x)*(b.b.x-b.a.x)+(a.b.y-a.a.y)*(b.b.x-b.a.x)*a.a.x-(a.b.x-a.a.x)*(b.b.y-b.a.y)*b.a.x)/((b.b-b.a)^(a.b-a.a)); return cpoint(x,y);}int main(){ freopen("in.txt","r",stdin); int cas; printf("INTERSECTING LINES OUTPUT\n"); scanf("%d",&cas); while(cas--) { scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&l1.a.x,&l1.a.y,&l1.b.x,&l1.b.y,&l2.a.x,&l2.a.y,&l2.b.x,&l2.b.y); if(parallel(l1,l2)) { if(zero(dist(l1.a,l2))) printf("LINE\n"); else printf("NONE\n"); } else { cpoint t = intersect(l1,l2); printf("POINT %.2lf %.2lf\n",t.x,t.y); } } printf("END OF OUTPUT\n"); return 0;}
- POJ 1269 Intersecting Lines(计算几何 求交点)
- poj 1269 Intersecting Lines 计算几何 直线求交点
- poj 1269 Intersecting Lines(计算几何)
- POJ 1269 Intersecting Lines --计算几何
- POJ 1269 Intersecting Lines(计算几何)
- poj 1269 Intersecting Lines(计算几何)
- POJ 1269 Intersecting Lines(计算几何)
- poj 1269 Intersecting Lines 计算几何
- POJ 1269 Intersecting Lines 简单计算几何
- poj 1269 Intersecting Lines(计算几何)
- POJ 1269 Intersecting Lines(计算几何)
- POJ 1269 Intersecting Lines 计算几何基础
- POJ 1269 Intersecting Lines(计算几何 直线交点 点在直线上 直线平行)
- poj 1269 Intersecting Lines(判断线段相交,并求交点)
- poj 1269 Intersecting Lines(判断直线相交 求交点)
- poj 1269 Intersecting Lines (求直线交点)
- POJ 1269 Intersecting Lines 求两直线交点
- POJ 1269 Intersecting Lines 叉积(求直线交点)
- 可重入函数与不可重入函数详解
- hdu 4389
- 笑话一则【转微博】
- Linux内核IP Queue机制的分析(二)——用户态处理并回传数据包
- 2011年北京区域赛A题
- POJ 1269 Intersecting Lines(计算几何 求交点)
- 数组指针和指针数组的区别
- 磁珠的作用以及和电感的区别
- 【HGE 教程04】游戏地图绘制 平面地图
- 教你在Windows上体验Firefox OS
- SQL Server 连接字符串和身份验证 学习
- 信号实现等待另一个进程
- SSH原理与运用(1)
- C语言笔试题(12)——猴子吃桃问题