判断两直线是否相交的叉积方法

 

struct point
{
    double x,y;
};

struct line
{
    point a,b;
}lines[110];

double chaji(point a,point b,point c,point d)
{
    return (b.x-a.x)*(d.y-c.y)-(b.y-a.y)*(d.x-c.x);
}

bool isin(line l1,line l2)
{
    if(chaji(l1.a,l2.a,l1.a,l1.b)*chaji(l1.a,l1.b,l1.a,l2.b)>=0&&chaji(l2.a,l1.b,l2.a,l2.b)*chaji(l2.a,l2.b,l2.a,l1.a)>=0)
        return true;
    return false;
}

 

posted @ 2016-08-08 13:57  相儒以沫  阅读(1364)  评论(0编辑  收藏  举报