利用叉积,如果点在三角形内部的话,则顺序处理全部边的话,这个点都在边的同一侧,直接用叉积判断
double det(double x1,double y1,double x2,double y2){
return x1*y2-x2*y1;
}
//x0,y0为需要的检查点,其他点顺时针顺序
bool check(double x0,double y0,double x1,double y1,double x2,double y2,double x3,double y3){
if(det(x0-x1,y0-y1,x2-x1,y2-y1)>=0&&det(x0-x2,y0-y2,x3-x2,y3-y2)>=0&&det(x0-x3,y0-y3,x1-x3,y1-y3)>=0)return true;
return false;
}