Intersecting Lines直线相交
来源:互联网 发布:基于c语言的win32api 编辑:程序博客网 时间:2024/05/28 15:02
Description
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 plane will intersect in one of three ways: 1) no intersection because they are parallel, 2) intersect in a line because they are on top of one another (i.e. they are the same line), 3) intersect in a point. In this problem you will use your algebraic knowledge to create a program that determines how and where two lines intersect.
Your program will repeatedly read in four points that define two lines in the x-y plane and determine how and where the lines intersect. All numbers required by this problem will be reasonable, say between -1000 and 1000.
Input
The first line contains an integer N between 1 and 10 describing how many pairs of lines are represented. The next N lines will each contain eight integers. These integers represent the coordinates of four points on the plane in the order . Thus each of these input lines represents two lines on the plane: the line through and and the line through and . The point is always distinct from . Likewise with and .
Output
There should be N+2 lines of output. The first line of output should read INTERSECTING LINES OUTPUT. There will then be one line of output for each pair of planar lines represented by a line of input, describing how the lines intersect: none, line, or point. If the intersection is a point then your program should output the x and y coordinates of the point, correct to two decimal places. The final line of output should read ``END OF OUTPUT".
Sample Input
50 0 4 4 0 4 4 05 0 7 6 1 0 2 35 0 7 6 3 -6 4 -32 0 2 27 1 5 18 50 3 4 0 1 2 2 5
Sample Output
INTERSECTING LINES OUTPUTPOINT 2.00 2.00NONELINEPOINT 2.00 5.00POINT 1.07 2.20END OF OUTPUT
#define DeBUG#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <algorithm>#include <vector>#include <stack>#include <queue>#include <string>#include <set>#include <sstream>#include <map>#include <bitset>using namespace std ;#define zero {0}#define INF 0x3f3f3f3f#define EPS 1e-9typedef long long LL;const double PI = acos(-1.0);//#pragma comment(linker, "/STACK:102400000,102400000")inline int sgn(double x){ return fabs(x) < EPS ? 0 : (x < 0 ? -1 : 1);}#define N 100005struct Point{ double x, y; Point () {} Point(double a, double b) { x = a; y = b; }};typedef Point Vec;Vec operator + (Vec a, Vec b)//点加法{ return Vec(a.x + b.x, a.y + b.y);}Vec operator - (Vec a, Vec b)//点减法{ return Vec(a.x - b.x, a.y - b.y);}Vec operator * (Vec a, double p)//点与常数相乘{ return Vec(a.x * p, a.y * p);}bool operator == (Point a, Point b)//点相等判断{ return sgn(a.x - b.x) == 0 && sgn(a.y - b.y) == 0;}inline double crossDet(Vec a, Vec b)//叉乘{ return a.x * b.y - a.y * b.x;}inline double dotDet(Vec a, Vec b)//点乘{ return a.x * b.x + a.y * b.y;}Vec getvec(Point a, Point b){ return Point(b.x - a.x, b.y - a.y);}Point lineIntersect(Point P, Vec v, Point Q, Vec w)//直线相交返回交点{ Vec u = P - Q; double t = crossDet(w, u) / crossDet(v, w); return P + v * t;}inline bool onLine(Point x, Point a, Point b)//叉积为0三点共线 { return sgn(crossDet(a - x, b - x)) == 0;}int main(){#ifdef DeBUGs freopen("C:\\Users\\Sky\\Desktop\\1.in", "r", stdin);#endif int T; scanf("%d", &T); printf("INTERSECTING LINES OUTPUT\n"); while (T--) { Point p[10]; for (int i = 0; i < 4; i++) { scanf("%lf%lf", &p[i].x, &p[i].y); } Vec a = getvec(p[0], p[1]); Vec b = getvec(p[2], p[3]); if (sgn(crossDet(a, b)) == 0 && (onLine(p[0],p[2],p[3]))//叉积为0且有一点共线 ) { printf("LINE\n"); } else if (sgn(crossDet(a, b)) == 0)//平行情况 { printf("NONE\n"); } else//套版不解释 { printf("POINT %.2lf %.2lf\n", lineIntersect(p[0], p[0] - p[1], p[2], p[2] - p[3])); } } printf("END OF OUTPUT\n"); return 0;}
- Intersecting Lines直线相交
- poj 1269 Intersecting Lines--直线相交
- POJ 1269 Intersecting Lines 判断直线相交
- POJ 1269Intersecting Lines 直线相交判断
- poj 1269 Intersecting Lines 【直线相交】
- Intersecting Lines(直线相交判断,求相交交点)
- Intersecting Lines(poj1269,判断直线与直线相交)
- 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 1269Intersecting Lines (直线相交判断,求相交交点)
- Intersecting Lines(判断线段相交)
- POJ 1269 Intersecting Lines 判断直线间的状态(平行、重合、相交于一点)
- Android ScrollView与ListView,GridView共存冲突解决方案
- Thinkphp使用mongodb数据库实现多条件查询方法
- java,hashcode,equals
- Cognex VisionPro 安装详解
- PHP执行Curl时报错提示CURL ERROR: Recv failure: Connection reset by peer
- Intersecting Lines直线相交
- Cocos2dx制作2048(3.数字相加逻辑)
- virbr0卸载
- 利用DHT网络原理制作bt采集蜘蛛
- 全栈JavaScript之路(一) 理解 DOM
- JDK 7 中的 Fork/Join 模式
- Google的Java常用类库 Guava
- 我自己的心情我自知道能理解自己的人太少了
- safe update