Portal: Intersecting Lines
Test instructions: Gives the n set of lines, each group of 2 straight lines, to find out whether the line intersects. If the collinear outputs line, the intersection enters point coordinates, otherwise the output is none.
Analysis: Template naked title, directly on the template ...
#include <iostream>#include<stdio.h>#include<string.h>#include<algorithm>#include<queue>#include<map>#include<vector>#include<Set>#include<string>#include<math.h>using namespacestd;Const DoubleEPS = 1e-8;Const DoublePI = ACOs (-1.0);Const intN = the;intSgnDoublex) { if(Fabs (x) < EPS)return 0; if(X <0)return-1; Else return 1;}structpoint{Doublex, y; Point () {}, point (Double_x,Double_y) {x= _x;y =_y; } Pointoperator-(ConstPoint &b)Const { returnPoint (X-b.x,y-b.y); } //Cross Product Double operator^(ConstPoint &b)Const { returnx*b.y-y*b.x; }};structline{Point S,e; Line () {} line (point _s,point _e) {s= _s;e =_e; } //two intersection of lines to find intersections//The first value of 0 indicates that the line is coincident, 1 is parallel, 0 is intersecting, and 2 is intersecting//only the first value is 2 o'clock, and the intersection makes sense.pair<int,point>operator& (ConstLine &b)Const{Point res=s; if(SGN (S-E) ^ (B.S-B.E)) = =0) { if(SGN (S-B.E) ^ (B.S-B.E)) = =0) returnMake_pair (0, res);//Coincident Else returnMake_pair (1, res);//Parallel } 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); }}; Line seg[Ten];intMain () {intT; scanf ("%d",&T); Puts ("intersecting LINES OUTPUT"); while(t--) { for(intI=1; i<=2; i++) { Doublea,b,c,d; scanf ("%LF%LF%LF%LF",&a,&b,&c,&d); Seg[i]=Line (point (b), point (C,d)); } pair<int,point> p=seg[1]&seg[2]; if(p.first==0) puts (" Line"); Else if(p.first==1) puts ("NONE"); Else{printf ("Point %.2lf%.2lf\n", P.SECOND.X,P.SECOND.Y); }} puts ("END of OUTPUT"); return 0;}
View Code
poj1269 (Straight line intersection)