# include <iostream>
# include <cstdlib>
using namespace std;
# define min(x,y) ((x)<(y)?(x):(y))
# define max(x,y) ((x)>(y)?(x):(y))
const int N=100001;
int n;
struct point
{
float x;
float y;
};
float direct(point i,point j,point k) //计算叉积
{
return (k.x-i.x)*(j.y-i.y)-(j.x-i.x)*(k.y-i.y);
}
int onsegment(point a,point b,point c) //共线时,判断点是否落在线段上
{
float minx=min(a.x,b.x);
float maxx=max(a.x,b.x);
float miny=min(a.y,b.y);
float maxy=max(a.y,b.y);
return c.x>=minx&&c.x<=maxx&&c.y>=miny&&c.y<=maxy;
}
int f(point p1,point q1,point p2,point q2)
{
float d1=direct(p2,q2,p1);
float d2=direct(p2,q2,q1);
float d3=direct(p1,q1,p2);
float d4=direct(p1,q1,q2);
if(d1*d2<0&&d3*d4<0)
return true;
else if(d1==0&&onsegment(p2,q2,p1))
return true;
else if(d2==0&&onsegment(p2,q2,q1))
return true;
else if(d3==0&&onsegment(p1,q1,p2))
return true;
else if(d4==0&&onsegment(p1,q1,q2))
return true;
return false;
}
int main()
{
int T;
cin>>T;
while(T--){
point a,b,c,d;
cin>>a.x>>a.y>>b.x>>b.y>>c.x>>c.y>>d.x>>d.y;
if(f(a,b,c,d)){
cout<<"Yes"<<endl;
}else{
cout<<"No"<<endl;
}
}
return 0;
}
线段相交模板
最新推荐文章于 2022-04-29 09:51:26 发布