【模板】【计几】判断点是否在凸包内

 1 bool is_in(Point p,Point ch [],int n){
 2     //n>=2 
 3     int a = 1,b = n-1,c;
 4     if(cross(ch[0],ch[a],ch[b]) > 0) swap(a,b);
 5     // is_in allow on edge -> if( cross() > 0 || cross() < 0 )
 6     if( cross(ch[0],ch[a],p) >= 0 || cross(ch[0],ch[b],p) <= 0 ) return 0;
 7     while( abs(a-b) > 1){
 8         c = (a+b)/2;
 9         if( cross(ch[0],ch[c],p) > 0) b = c;
10         else a = c;
11     }
12     //is_in allow on edge -> return cross() <= 0
13     return cross(ch[a],ch[b],p) < 0;
14 }

 

posted @ 2020-03-25 19:38  小布鞋  阅读(839)  评论(0编辑  收藏  举报