判断线段是否相交

 1 double mul(node a,node b,node c)//c叉积运算
 2 {
 3     return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
 4 }
 5 int judge(node a,node b,node c,node d)//判断线段两个点是否在一条线段的两端,要对两条线段都判断
 6 {
 7     double p1=mul(a,c,b);
 8     double p2=mul(a,d,b);
 9     if (p1*p2<=0&&!(p1==0&&p2==0)) return 1;//这里有题目可能两条线段重合,所以
10     return 0;
11 }

 

posted on 2013-12-16 16:30  forgot93  阅读(145)  评论(0编辑  收藏  举报

导航