判断两条线段AB CD是否相交 (判断ACBD是否能构成凸多边形)
线段AB与线段CD 是否相交 顺序叉积 AC CB BD DA (AC叉CB CB叉BD BD叉DA DA叉AC)
记一下叉积正负的个数
#include <iostream>
using namespace std;
int cross(int x1,int y1,int x2,int y2,int x3,int y3)
{
return (x1-x3)*(y2-y3)-(x2-x3)*(y1-y3);
}
int main()
{
int x1,y1,x2,y2,x3,y3,x4,y4;
while(cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4)
{
int c[4];
c[0]=cross(x1,y1,x2,y2,x3,y3);
c[1]=cross(x1,y1,x2,y2,x4,y4);
c[2]=cross(x3,y3,x4,y4,x1,y1);
c[3]=cross(x3,y3,x4,y4,x2,y2);
int sum1=0,sum2=0;
for(int i=0;i<4;i++)
{
if(c[i]>0) sum1++;
if(c[i]<0) sum2++;
}
if(sum1>0&&sum2>0)
cout<<"no"<<endl;
else
cout<<"yes"<<endl;
}
return 0;
}