struct Line {
double x1,y1,x2,y2;
};
bool check(Line l1,Line l2)
{
//快速排斥实验
if(max(l1.x1,l1.x2)<min(l2.x1,l2.x2)||max(l1.y1,l1.y2)<min(l2.y1,l2.y2)||
min(l1.x1,l1.x2)>max(l2.x1,l2.x2)||min(l1.y1,l1.y2)<max(l2.y1,l2.y2))
return 0;
//跨立实验
if((((l1.x1-l2.x1)*(l2.y2-l2.y1)-(l1.y1-l2.y1)*(l2.x2-l2.x1))*
((l1.x2-l2.x1)*(l2.y2-l2.y1)-(l1.y2-l2.y1)*(l2.x2-l2.x1)))>0||
(((l2.x1-l1.x1)*(l1.y2-l1.y1)-(l2.y1-l1.y1)*(l1.x2-l1.x1))*
((l2.x2-l1.x1)*(l1.y2-l1.y1)-(l2.y2-l1.y1)*(l1.x2-l1.x1)))>0)
return 0;
return 1;
}
怒推一篇大佬博客,里面有详细解析。