51nod 1264 segment Intersection (geometry)

Source: Internet
Author: User

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)

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.