POJ-1269 Intersecting Lines

Posted nianheng

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了POJ-1269 Intersecting Lines相关的知识,希望对你有一定的参考价值。

题意:判断两条直线相交,平行还是重合

#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct Point{
    double x,y;
    Point(double xx=0,double yy=0){
        x=xx,y=yy;
    }
}s1,s2,t1,t2;
struct Vector{
    double x,y;
    Vector(double xx=0,double yy=0){
        x=xx,y=yy;
    }
};
int t;
int dcmp(double x){return fabs(x)<1e-9?0:(x>0?1:-1);}
Vector operator - (Point a,Point b){return Vector(a.x-b.x,a.y-b.y);}
Vector operator * (double p,Vector a){return Vector(a.x*p,a.y*p);}
Point operator + (Point a,Vector b){return Point(a.x+b.x,a.y+b.y);}
double operator * (Vector a,Vector b){return a.x*b.y-a.y*b.x;}
double len(Vector a){return sqrt(a.x*a.x+a.y*a.y);}
double distl(Point p,Point a,Point b){
    Vector v1=b-a,v2=p-a;
    return v1*v2/len(v1);
}
Point fla(Point a,Point b,Point c,Point d){
    Vector v1=b-a,v2=d-c,v3=a-c;
    return a+v2*v3/(v1*v2)*v1;
}
int check(Point a,Point b,Point c,Point d){
    Vector x=b-a,y=d-c;
    Vector v1=c-a,v2=d-a;
    int ax=dcmp(x*v1),bx=dcmp(x*v2);
    v1=a-c,v2=b-c;
    int ay=dcmp(y*v1),by=dcmp(y*v2);
    if((ax==bx&&ax==0)||(ay==by&&ay==0)) return 0;
    if((ax==bx&&(distl(c,a,b)==distl(d,a,b)))||(ay==by&&distl(a,c,d)==distl(b,c,d))) return 1;
    return 2;
}
int main(){
    scanf("%d",&t);
    printf("INTERSECTING LINES OUTPUT
");
    while(t--){
        scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&s1.x,&s1.y,&t1.x,&t1.y,&s2.x,&s2.y,&t2.x,&t2.y);
        int x=check(s1,t1,s2,t2);
        if(!x) printf("LINE
");
        if(x==1) printf("NONE
");
        if(x==2){
            Point b=fla(s1,t1,s2,t2);
            printf("POINT %.2lf %.2lf
",b.x,b.y);
        }
    }
    printf("END OF OUTPUT
");
    return 0;
}

以上是关于POJ-1269 Intersecting Lines的主要内容,如果未能解决你的问题,请参考以下文章

●POJ 1269 Intersecting Lines

POJ 1269Intersecting Lines [计算几何]

Intersecting Lines POJ - 1269

POJ1269 Intersecting Lines[线段相交 交点]

[POJ 1269]Intersecting Lines

POJ-1269 Intersecting Lines