int dblcmp(double x){
if( fabs(x) < eps )
return 0;
return x > 0 ? 1 : -1;
}
double dot(double x1,double y1,double x2,double y2){
return x1*y2-y1*x2;
}
double cro(point a,point b,point c){
return dot( b.x-a.x , b.y-a.y , c.x-a.x , c.y-a.y );
}
bool on(point a,point b,point c){
double xmin,xmax,ymin,ymax;
if( a.x < b.x ){
xmin = a.x;
xmax = b.x;
}
else{
xmin = b.x;
xmax = a.x;
}
if( a.y < b.y ){
ymin = a.y;
ymax = b.y;
}
else{
ymin = b.y;
ymax = a.y;
}
if( c.x < xmin || c.x > xmax || c.y < ymin || c.y > ymax )
return false;
return true;
}
bool crossok(point a,point b,point c,point d){ //线段是否相交
double d1 = cro(c,d,a);
double d2 = cro(c,d,b);
double d3 = cro(a,b,c);
double d4 = cro(a,b,d);
if( d1*d2 < 0 && d3*d4 < 0 )
return true;
if( d1 == 0 && on(c,d,a) )
return true;
if( d2 == 0 && on(c,d,b) )
return true;
if( d3 == 0 && on(a,b,c) )
return true;
if( d4 == 0 && on(a,b,d) )
return true;
return false;
}
判断线段是否相交
最新推荐文章于 2023-11-08 20:12:11 发布