"POJ" Intersecting Lines (computational geometry)

Source: Internet
Author: User

http://poj.org/problem?id=1269

I would say this water problem I push formula + code with 1.5H?

Fortunately, 1 A in the new year. ~ ~ ~

#include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream > #include <algorithm> #include <queue> #include <set> #include <map>using namespace std; typedef long long ll; #define PII pair<int, int> #define MKPII make_pair<int, int> #define PDI Pair<double, in T> #define MKPDI make_pair<double, int> #define PLI pair<ll, int> #define MKPLI make_pair<ll, int># Define REP (I, n) for (int i=0; i< (n); ++i) #define FOR1 (i,a,n) for (int i= (a); i<= (n); ++i) #define FOR2 (i,a,n) for (int i= (a);i< (n); ++i) #define FOR3 (i,a,n) for (int i= (a); i>= (n); i.) #define FOR4 (i,a,n) for (int i= (a);i> (n); Define CC (I,a) memset (i,a,sizeof (i)) #define READ (a) a=getint () #define PRINT (a) printf ("%d", a) #define DBG (x) cout <& Lt (#x) << "=" << (x) << endl#define error (x) (!) ( x) puts ("error"): 0) #define PRINTARR2 (A, B, c) For1 (_, 1, b) {For1 (__, 1, c) cout << a[_][__]; cout &LT;&LT Endl } #define PRINTARR1 (A, B) For1 (_, 1, b) cout << a[_] << ' \ t '; cout << endlinline const int Getint () {int r=0, k=1; char C=getchar (); for (; c< ' 0 ' | | C> ' 9 '; C=getchar ()) if (c== '-') k=-1; for (; c>= ' 0 ' &&c<= ' 9 '; C=getchar ()) r=r*10+c-' 0 '; return k*r; }inline const int MAX (const int &a, const int &b) {return a>b?a:b;} inline const int min (const int &AMP;A, const int &b) {return a<b?a:b;} Const Double Eps=1e-6;struct Pt {double x, y; Pt (double _x=0, double _y=0): X (_x), Y (_y) {}};int dcmp (double A) {if (ABS (a) <eps) return 0; return a<0?-1:1;} typedef Pt VT; VT operator+ (const PT &AMP;A, const PT &b) {return Vt (a.x+b.x, a.y+b.y);} VT operator-(const PT &AMP;A, const PT &b) {return Vt (a.x-b.x, a.y-b.y);} VT operator* (const Pt &a, const double &b) {return Vt (a.x*b, a.y*b);} BOOL operator== (const PT &AMP;A, const PT &b) {return dcmp (a.x-b.x) ==0 && dcmp (A.Y-B.Y) ==0;} Double Cross (VT A, VT b) {return a.x*b.y-b.x*a.y;} struct line {Pt p; Vt v; Line () {}line (pt &a, pt &b) {p=a; v=b-a;}}; PT GETLLP (line &a, line &b) {static Pt p, q;static Vt u, W, v;p=a.p; q=b.p;v=a.v; w=b.v;u=p-q;double T1=cross (W, u )/cross (V, W); return p+v*t1;} -1:xiangjiao 0:chonghe 1:pingxingint lineandline (line &p, line &q) {if (dcmp (P.V, Q.V))!=0) Return-1;ret Urn dcmp (Cross (Q.P-P.P, q.v)) ==0 && dcmp (Cross (Q.P-P.P, P.V)) ==0;} int main () {int n;while (~scanf ("%d", &n)) {puts ("intersecting LINES OUTPUT"); Line l[2]; Pt P[4];while (n--) {rep (k, 4) scanf ("%lf%lf", &p[k].x, &p[k].y); L[0]=line (P[0], p[1]); L[1]=line (p[2], p[3]); int C=lineandline (l[0], l[1]), if (c==-1) {Pt PT=GETLLP (l[0], l[1]); printf ("Point%.2f%.2f\n", Pt.x, Pt.y);} else if (c==0) puts ("NONE"), Else puts ("line");} Puts ("END of OUTPUT");} return 0;}

  

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

"POJ" Intersecting Lines (computational geometry)

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.