//学习判定两直线关系:平行 重合 相交
//求交点
#include<iostream>
#include <math.h>
using namespace std;
#define eps 1e-8
#define zero(x) (((x)>0?(x):-(x))<eps)
struct point{double x,y;};
struct line{point a,b;};
double xmult(line u,line v){
return (u.b.x-u.a.x)*(v.b.y-v.a.y)-(v.b.x-v.a.x)*(u.b.y-u.a.y);
}
//计算两直线交点,注意事先判断直线是否平行!
point intersection(line u,line v){
point ret=u.a;
double t=((u.a.x-v.a.x)*(v.a.y-v.b.y)-(u.a.y-v.a.y)*(v.a.x-v.b.x))
/((u.a.x-u.b.x)*(v.a.y-v.b.y)-(u.a.y-u.b.y)*(v.a.x-v.b.x));
ret.x+=(u.b.x-u.a.x)*t;
ret.y+=(u.b.y-u.a.y)*t;
return ret;
}
int main()
{
line u,v;
int n;
scanf("%d",&n);
printf("INTERSECTING LINES OUTPUT\n");
while(n--)
{
scanf("%lf%lf%lf%lf",&(u.a.x),&(u.a.y),&(u.b.x),&(u.b.y));
scanf("%lf%lf%lf%lf",&(v.a.x),&(v.a.y),&(v.b.x),&(v.b.y));
double a1,b1,c1,a2,b2,c2;
//xishu
a1=u.a.y-u.b.y;
b1=-(u.a.x-u.b.x);
c1=u.a.x*u.b.y-u.a.y*u.b.x;
a2=v.a.y-v.b.y;
b2=-(v.a.x-v.b.x);
c2=v.a.x*v.b.y-v.a.y*v.b.x;
//if( fabs(xmult(u,v))<eps)
if(fabs(a1*b2-a2*b1)<eps)
{
if( fabs(a1*c2-a2*c1)<eps && fabs(b1*c2-b2*c1)<eps )
printf("LINE\n");
else printf("NONE\n");
}
else
{
point res;
//res=intersection(u,v);
res.x=(b1*c2-b2*c1)/(a1*b2-a2*b1);
res.y=(a2*c1-a1*c2)/(a1*b2-a2*b1);
printf("POINT %.2lf %.2lf\n",res.x,res.y);
}
}
printf("END OF OUTPUT\n");
return 0;
}
posted on 2009-10-04 18:15
wyiu 阅读(141)
评论(0) 编辑 收藏 引用 所属分类:
POJ