intersecting Lines
Time Limit: 1000MS |
|
Memory Limit: 10000K |
Total Submissions: 12421 |
|
Accepted: 5548 |
Description
We all know this a pair of distinct points on a plane defines a line and that a pair of lines on a plane would intersect in One of three ways:1) no intersection because they is parallel, 2) intersect in a line because they is on top of one Other (i.e they is the same line), 3) intersect at a point. In the problem you'll use your algebraic knowledge to create a program that determines how and where the lines intersec T.
Your program would repeatedly read in four points that define, lines in the X-y plane and determine how and where the Li NES intersect. All numbers required by this problem would be reasonable, say between-1000 and 1000.
Input
The first line contains an integer N between 1 and ten describing how many pairs of lines is represented. The next N lines would 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, lines on the Plane:the line through (x1,y1) and (X2,y2) and the line Throug H (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'll then being one line of output for each pair of planar lines represented by a line of input, describing how the Lin Es 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 both Decima L 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
Source
Mid-Atlantic 1996
Test instructions: Given 1-10 sets of straight lines, determine the relationship of each group of straight lines, if the intersection output intersection coordinates, two decimal places are retained, if parallel, output ' NONE '; if coincident, output ' line ';
The output format is described in standard output.
1#include <iostream>2#include <cstdio>3#include <cmath>4#include <cstdlib>5#include <cstring>6#include <math.h>7#include <algorithm>8#include <cctype>9#include <string>Ten#include <map> One#include <Set> A #definell Long Long - using namespacestd; - Const DoubleEPS = 1e-8; the intSgnDoublex) - { - if(Fabs (x) < EPS)return 0; - if(X <0)return-1; + Else return 1; - } + struct Point A { at Doublex, y; - Point () {} -Point (Double_x,Double_y) - { -x = _x;y =_y; - } inPointoperator-(ConstPoint &b)Const - { to returnPoint (X-b.x,y-b.y); + } - Double operator^(ConstPoint &b)Const the { * returnx*b.y-y*b.x; $ }Panax Notoginseng Double operator*(ConstPoint &b)Const - { the returnx*b.x + y*b.y; + } A }; the + struct Line - { $ Point s,e; $ Line () {} - Line (Point _s,point _e) - { thes = _s;e =_e; - }WuyiPair<point,int>operator& (ConstLine &b)Const the { -Point res =s; Wu if(SGN (S-E) ^ (B.S-B.E)) = =0) - { About if(SGN (b.s-s) ^ (b.e-s)) = =0) $ returnMake_pair (Res,0);//Two line coincident - Else returnMake_pair (Res,1);//two straight line parallel - } - DoubleT = ((S-B.S) ^ (B.S-B.E))/((S-E) ^ (b.s-B.E)); ARes.x + = (e.x-s.x) *T; +Res.y + = (e.y-s.y) *T; the returnMake_pair (Res,2);//There are intersections - } $ }; the the intMainvoid) the { the intT; - DoubleX1,x2,x3,x4,y1,y2,y3,y4; inscanf"%d",&t); theprintf"intersecting LINES output\n"); the while(t--) About { thescanf"%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4); theLine L1 =Line (Point (X1,y1), point (X2,y2)); theLine L2 =Line (Point (X3,y3), point (X4,y4)); +Pair<point,int> ans = L1 &L2; - if(Ans.second = =2) printf ("Point %.2f%.2f\n", ANS.FIRST.X,ANS.FIRST.Y); the Else if(Ans.second = =0) printf ("line\n");Bayi Elseprintf"none\n"); the } theprintf"END of output\n"); - - return 0; the}
POJ 1269 intersecting Lines (judging the relationship between two straight lines and finding the intersection coordinates)