Topic Link: 51nod 1264 segment intersection
If two segments intersect, either one of the endpoints of one segment is met on another segment, or two segments are on a straight line extending across another segment. (If the point P1 is on one side of the line p3p4 and the point P2 is on the other side of the line, it is said that P1p2 crosses the line p3p4.) )
Cross-multiplication can be used to determine whether the P3P1, p3p2 are in different directions in the P3P4 (CIS, counterclockwise) (line segment p1p2 across the line p3p4) and P1P4, p1p3 whether in different directions of P1P2 (segment p3p4 across the line p1p2) to determine whether the intersection.
Judgment on the direction of the fork, come, reach out your right hand ...
1#include <cstdio>2 using namespacestd;3 structpoint{4 Doublex, y;5 };6 BOOLF (Point A, point B, point C, point D) {7 DoubleD1 = (a.x-c.x) * (D.Y-C.Y)-(A.Y-C.Y) * (d.x-c.x);8 DoubleD2 = (b.x-c.x) * (D.Y-C.Y)-(B.Y-C.Y) * (d.x-c.x);9 if(d1*d2<=0)return 1;Ten return 0; One } A BOOLCheck (point A, point B, point C, point D) { - if(!f (A,B,C,D))return 0; - if(!f (C,D,A,B))return 0; the return 1; - } - intMain () { - intT; + Point A, B, C, D; -scanf"%d", &t); + while(t--){ Ascanf"%LF%LF%LF%LF%LF%LF%LF%LF",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y,&d.x,&d.y); at if(check (a,b,c,d)) -Puts"Yes"); - ElsePuts"No"); - } - return 0; -}
View Code
51nod 1264 segment Intersection (geometry)