Http://www.51nod.com/onlineJudge/questionCode.html! Problemid = 1264
Directed area of a triangle:. x * B. Y + B. x * C. Y + C. x *. y-. x * C. y-C. x * B. y-B. x *. y;
The above result is two times the area of a triangle composed of three points A, B, and C.
If area is greater than 0, points A, B, and C are arranged counterclockwise.
If area is less than 0, points A, B, and C are arranged clockwise.
If Area = 0, vertices A, B, and C are collocated.
Determine whether line segments 1 (two endpoints A and B) are intersecting with line segments 2 (two endpoints C and D) only require A, B, C, A, B, whether the product of the directed area of D is less than 0, and whether the directed area of C, D, A, C, D, and B is less than 0.
Only when two line segments overlap, the directed area will be one of the positive and negative parts. Draw one and you will know.
The product of the intersection of the endpoints is equal to 0.
1 # include <cstdio> 2 3 struct point 4 {5 double X, Y; 6}; 7 double Dir (point a, point B, point C) // determine the directed area of a triangle as clockwise 8 {9 return. x * B. Y + B. x * C. Y + C. x *. y-. x * C. y-C. x * B. y-B. x *. y; 10} 11 bool connected (point a, point B, point C, point D) // determine the intersection of 12 {13 if (Dir (A, B, C) * Dir (a, B, d) <= 0 & Dir (D, C, A) * Dir (D, C, B) <= 0) return 1; // note that the intersection at the endpoint is equal to 014 return 0; 15} 16 17 int main () 18 {19 int t; 20 point a, B, c, d; 21 scanf ("% d", & T); 22 while (t --) 23 {24 scanf ("% lf", &. x, &. y, & B. x, & B. y, & C. x, & C. y, & D. x, & D. y); 25 if (connected (A, B, C, D) printf ("Yes \ n"); 26 else printf ("NO \ n "); 27} 28 return 0; 29}
Determining the intersection of line segments -- intersection of line segments in 51nod 1264