1 //Straight line intersection POJ 12692 3 //#include <bits/stdc++.h>4#include <iostream>5#include <cstdio>6#include <cstdlib>7#include <algorithm>8#include <math.h>9 using namespacestd;Ten #defineLL Long Long Onetypedef pair<int,int>PII; A Const DoubleINF =123456789012345.0; - ConstLL MOD =100000000LL; - Const intN =1e4+Ten; the #defineCLC (A, B) memset (A,b,sizeof (a)) - Const DoubleEPS = 1e-8; - voidFre () {freopen ("In.txt","R", stdin);} - voidFreout () {freopen ("OUT.txt","W", stdout);} +InlineintRead () {intx=0, f=1;CharCh=getchar (); while(ch>'9'|| ch<'0') {if(ch=='-') f=-1; Ch=getchar ();} while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; Ch=getchar ();}returnx*F;} - + intSgnDoublex) { A if(Fabs (x) < EPS)return 0; at if(X <0)return-1; - Else return 1; - } - structpoint{ - Doublex, y; - Point () {} inPoint (Double_x,Double_y) { -x = _x;y =_y; to } +Pointoperator-(ConstPoint &b)Const{ - returnPoint (X-b.x,y-b.y); the } * Double operator^(ConstPoint &b)Const{ $ returnx*b.y-y*b.x;Panax Notoginseng } - Double operator*(ConstPoint &b)Const{ the returnx*b.x + y*b.y; + } A }; the + structline{ - Point s,e; $ Line () {} $ Line (Point _s,point _e) { -S=_s;e=_e; - } thepair<int,point>operator& (ConstLine &b)Const{ -Point res=s;Wuyi if(SGN (S-E) ^ (B.S-B.E)) = =0){ the if(SGN (S-B.E) ^ (B.S-B.E)) = =0) - returnMake_pair (0, res); Wu Else returnMake_pair (1, res); - } About DoubleT= ((S-B.S) ^ (B.S-B.E))/((S-E) ^ (b.s-B.E)); $res.x+= (e.x-s.x) *T; -res.y+= (E.Y-S.Y) *T; - returnMake_pair (2, res); - } A }; + the intMain () { - intT; $scanf"%d",&T); the DoubleX1,x2,x3,x4,y1,y2,y3,y4; theprintf"intersecting LINES output\n"); the while(t--){ thescanf"%LF%LF%LF%LF%LF%LF%LF%LF",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4); -Line line1 =Line (Point (X1,y1), point (X2,y2)); inLine line2 =Line (Point (X3,y3), point (X4,y4)); thepair<int,point> Ans=line1 &line2; the if(ans.first==0) printf ("line\n"); About Else if(ans.first==1) printf ("none\n"); the Elseprintf"Point %.2f%.2f\n", ANS.SECOND.X,ANS.SECOND.Y); the } theprintf"END of output\n"); + return 0; -}
Straight line intersection POJ 1269