给出两条线段,判断这两条线段是否相交。
struct Point{
double x,y;
};
double mult(Point a, Point b, Point c)
{
return (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y);
}
bool intersect(Point aa, Point bb, Point cc, Point dd)//相交返回true,不相交返回false
{
if ( max(aa.x, bb.x)<min(cc.x, dd.x) ) return false;
if ( max(aa.y, bb.y)<min(cc.y, dd.y) ) return false;
if ( max(cc.x, dd.x)<min(aa.x, bb.x) ) return false;
if ( max(cc.y, dd.y)<min(aa.y, bb.y) ) return false;
if ( mult(cc, bb, aa)*mult(bb, dd, aa)<0 ) return false;
if ( mult(aa, dd, cc)*mult(dd, bb, cc)<0 ) return false;
return true;
}