Determining the intersection of line segments -- intersection of line segments in 51nod 1264

Source: Internet
Author: User

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

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.