判断重合,相交,平行三种关系
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct Point
{
double x,y;
Point(){}
Point(double _X,double _Y){
x = _X; y = _Y;
}
};
Point P1,P2,P3,P4;
Point Intersection(Point u1, Point u2, Point v1, Point v2)
{
Point ret = u1;
double t = ((u1.x-v1.x)*(v1.y-v2.y) - (u1.y-v1.y)*(v1.x-v2.x))
/ ((u1.x-u2.x)*(v1.y-v2.y) - (u1.y-u2.y)*(v1.x-v2.x));
ret.x += (u2.x-u1.x) * t;
ret.y += (u2.y-u1.y) * t;
return ret;
}
int main()
{
int n;
// freopen("in.txt","r",stdin);
while(scanf("%d",&n)!=EOF)
{
puts("INTERSECTING LINES OUTPUT");
for(int i=0;i<n;i++){
scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&P1.x,&P1.y,&P2.x,&P2.y,&P3.x,&P3.y,&P4.x,&P4.y);
if((P2.x-P1.x)*(P4.y-P3.y)==(P2.y-P1.y)*(P4.x-P3.x)){///判断是否平行
if((P4.y-P3.y)*(P1.y*P2.x-P1.x*P2.y)==(P2.y-P1.y)*(P3.y*P4.x-P3.x*P4.y)
&&(P4.x-P3.x)*(P1.y*P2.x-P1.x*P2.y)==(P2.x-P1.x)*(P3.y*P4.x-P3.x*P4.y))///重合
puts("LINE");
else///平行不重合
puts("NONE");
}
else{///相交
Point t=Intersection(P1,P2,P3,P4);
printf("POINT %0.2lf %0.2f\n",t.x,t.y);
}
}
puts("END OF OUTPUT");
}
return 0;
}