POJ 1269 segments intersect with segments

Source: Internet
Author: User

Intersecting Lines
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 13605 Accepted: 6049

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

/*POJ 1269 segments intersect with a segment and can be judged by the cross product, and then the intersection is calculated. hhh-2016-05-04 20:48:26*/#include <iostream> #include <vector># Include <cstring> #include <string> #include <cstdio> #include <queue> #include <cmath># Include <algorithm> #include <functional> #include <map>using namespace std; #define Lson (i<<1) #define Rson ((i<<1) | |) typedef LONG LONG ll;const int MAXN = 40010;double eps = 1e-8;int tot;int n,m;double x1,x2,    Y1,y2,x3,x4,y3,y4;int SGN (double x) {if (Fabs (x) < EPS) return 0;    if (x < 0) return-1; else return 1;}    struct point{double x, y;    Point () {}, point (int _x,int _y) {x = _x,y = _y;    } Point operator-(const point &b) const {return point (X-B.X,Y-B.Y);    } double operator ^ (const point &b) const {return x*b.y-y*b.x;    }};struct line{Point s,t;        Line () {} line (point _s,point _t) {s = _s;    t = _t; } pair<int,point> Operator & (const line&b) const {Point res = s; if (sgn (s-t) ^ (b.s-b.t)) = = 0)//cross product judgment {if (sgn (s-b.t) ^ (b.s-b.t)) = = 0) return m            Ake_pair (0,res);        else return Make_pair (1,res);        } Double ta = ((S-B.S) ^ (b.s-b.t))/((s-t) ^ (b.s-b.t));        Res.x + = (t.x-s.x) *ta;        Res.y + = (t.y-s.y) *ta;    Return Make_pair (2,res); }};int TANS[MAXN]; Line LINE[MAXN]; Point PO[MAXN];    Point P;struct pair<int,point> t;int Main () {int t;    int flag= 1;    scanf ("%d", &t);        while (t--) {if (flag) printf ("Intersecting LINES output\n");        Flag = 0;        scanf ("%lf%lf%lf%lf%lf%lf%lf%lf", &x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);        Line L1 = line (point (X1,y1), point (X2,y2));        Line L2 = line (point (X3,y3), point (X4,y4));        t = (L1&AMP;L2);        if (T.first = = 0) printf ("line\n");            else if (T.first = = 1)printf ("none\n");            else {printf ("point");            Point TP = T.second;        printf ("%.2f%.2f\n", tp.x,tp.y);    } if (t==0) printf ("END of output\n"); } return 0;}

  

POJ 1269 segments intersect with segments

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.