POJ 1269 Intresting Lines(直线之间的关系及求交点)
2017-11-19 10:27
399 查看
Intersecting Lines
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 17023 Accepted: 7325
Description
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 x1y1x2y2x3y3x4y4. Thus each of these input lines represents two lines on the plane: the line through (x1,y1) and (x2,y2) and the line through (x3,y3) and (x4,y4). The point (x1,y1) is always distinct from (x2,y2). Likewise with (x3,y3) and (x4,y4).
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
5
0 0 4 4 0 4 4 0
5 0 7 6 1 0 2 3
5 0 7 6 3 -6 4 -3
2 0 2 27 1 5 18 5
0 3 4 0 1 2 2 5
Sample Output
INTERSECTING LINES OUTPUT
POINT 2.00 2.00
NONE
LINE
POINT 2.00 5.00
POINT 1.07 2.20
END OF OUTPUT
Source
Mid-Atlantic 1996
PS:用C++交
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 17023 Accepted: 7325
Description
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 x1y1x2y2x3y3x4y4. Thus each of these input lines represents two lines on the plane: the line through (x1,y1) and (x2,y2) and the line through (x3,y3) and (x4,y4). The point (x1,y1) is always distinct from (x2,y2). Likewise with (x3,y3) and (x4,y4).
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
5
0 0 4 4 0 4 4 0
5 0 7 6 1 0 2 3
5 0 7 6 3 -6 4 -3
2 0 2 27 1 5 18 5
0 3 4 0 1 2 2 5
Sample Output
INTERSECTING LINES OUTPUT
POINT 2.00 2.00
NONE
LINE
POINT 2.00 5.00
POINT 1.07 2.20
END OF OUTPUT
Source
Mid-Atlantic 1996
PS:用C++交
#include <cstdio> #include <iostream> #include <cstring> #include <cmath> #include <algorithm> #include <queue> #include <map> #include <stack> #include <vector> #define maxn 10010 #define maxe 100010 typedef long long ll; using namespace std; const double eps=1e-5; const int inf=0x3f3f3f3f3f; struct Point { int x,y; Point(){}; Point(int a,int b) { x=a,y=b; } void input() { scanf("%d%d",&x,&y); } Point operator +(Point a) { Point b(x+a.x,y+a.y); return b; } Point operator -(Point a) { Point b(x-a.x,y-a.y); return b; } int operator *(Point a) { return x*a.x+y*a.y; } int operator ^(Point a) { return x*a.y-y*a.x; } bool operator <(Point a) { return x<a.x; } }; struct Line { Point a,b; double k,d; bool flag; void prepare() { if(a.x-b.x!=0) k=(a.y-b.y)*1.0/(a.x-b.x),flag=true,d=a.y-k*a.x; else flag=false,d=a.x; } Line(Point st,Point ed) { a=st; b=ed; prepare(); } Line(){}; void input() { a.input(); b.input(); prepare(); } int operator *(Line l) { return (a-b)*(l.a-l.b); } int operator ^( Line l) { return (a-b)^(l.a-l.b); } Point intersect(Line l) { Point r;double x,y; if(!flag&&l.flag) { x=d; y=l.k*x+l.d; } else if(flag&&!l.flag) { x=l.d; y=k*x+d; } else { x=(l.d-d)/(k-l.k); y=k*x+d; } printf("POINT %.2lf %.2lf\n",x,y); r.x=x; r.y=y; return r; } }; int mul(Point a,Point b,Point c) { return (b-a)^(c-a); } int main() { Line l1,l2; int t; freopen("in.txt","r",stdin); scanf("%d",&t); puts("INTERSECTING LINES OUTPUT"); while(t--) { l1.input(); l2.input(); if((l1^l2)==0) { if(mul(l1.a,l1.b,l2.a)==0) { puts("LINE");continue; } else { puts("NONE");continue; } } else { Point jiao=l1.intersect(l2); } } puts("END OF OUTPUT"); return 0; }
相关文章推荐
- POJ1269(计算几何基础-直线与直线之间的关系与它们的交点)
- POJ 1269 Intersecting Lines 判断直线关系(相交(求交点),重合,平行)
- POJ 1269 Intersecting Lines 判断直线关系(相交(求交点),重合,平行)
- poj 1269 Intersecting Lines(判断两直线关系,并求交点坐标)
- Intersecting Lines--POJ1269(判断两条直线的关系 && 求两条直线的交点)
- POJ 1269 Intersecting Lines (两直线之间的位置关系)
- poj 1269 判断两直线的关系并求交点
- poj 1269判断两条直线的位置关系 以及求交点
- POJ 1269 Intersecting Lines(直线位置关系,水)
- POJ 1269 直线位置关系的判断
- POJ 1269 判断直线的关系:相交,平行,重合
- POJ 1269 Intersecting Lines(计算几何 直线交点 点在直线上 直线平行)
- Intersecting Lines - POJ 1269(判断平面上两条直线的关系)
- POJ 1269(计算几何初步——简单处理解析几何,求直线交点)
- poj 1269 判直线共线,平行,求交点
- POJ 1269 判断直线和直线关系
- POJ1269——Intersecting Lines(计算几何,直线关系判断)
- POJ 1269 Intersecting Lines(判断两条直线关系)
- poj 1269 Intersecting Lines 求直线交点 判断直线平行共线
- (计算几何step8.1.2.2)POJ 1269 Intersecting Lines(使用叉积来计算两条直线的交点)