# [POJ1269]Intersecting Lines（计算几何）

## 代码

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;

const double eps=1e-9;
int dcmp(double x)
{
if (x<=eps&&x>=-eps) return 0;
return (x>0)?1:-1;
}
struct Vector
{
double x,y;
Vector(double X=0,double Y=0)
{
x=X,y=Y;
}
};
typedef Vector Point;
struct Line
{
Point p;
Vector v;
Line(Point P=Point(0,0),Vector V=Vector(0,0))
{
p=P,v=V;
}
};
Vector operator + (Vector A,Vector B) {return Vector(A.x+B.x,A.y+B.y);}
Vector operator * (Vector A,double a) {return Vector(A.x*a,A.y*a);}

int T;
double a,b,c,d;

double Cross(Vector A,Vector B)
{
return A.x*B.y-A.y*B.x;
}
Point GIL(Line A,Line B)
{
Vector v=A.v,w=B.v,u=Vector(A.p.x-B.p.x,A.p.y-B.p.y);
double t=Cross(w,u)/Cross(v,w);
return A.p+A.v*t;
}
int main()
{
puts("INTERSECTING LINES OUTPUT");
scanf("%d",&T);
while (T--)
{
scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
Vector v1=Vector(c-a,d-b);
Line A=Line(Point(a,b),v1);
scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
Vector v2=Vector(c-a,d-b);
Line B=Line(Point(a,b),v2);
Vector v3=Vector(A.p.x-B.p.x,A.p.y-B.p.y);
double x=Cross(v1,v2);
double y=Cross(v1,v3);
if (!dcmp(x)&&!dcmp(y)) puts("LINE");
else if (!dcmp(x)) puts("NONE");
else
{
Point ans=GIL(A,B);
printf("POINT %.2lf %.2lf\n",ans.x,ans.y);
}
}
puts("END OF OUTPUT");
}