poj1269 (Straight line intersection)

Source: Internet
Author: User

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)

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.