struct point { double x,y; }a[Max]; double chaji(point p1,point p2) { return p1.x*p2.y-p1.y*p2.x; } double dot(point p1,point p2) { return p1.x*p2.x-p1.y*p2.y; } int ccw(point p0,point p1,point p2) { p1.x=p1.x-p0.x,p1.y=p1.y-p0.y; p2.x=p2.x-p0.x,p2.y=p2.y-p0.y; if(chaji(p1,p2)>0) return 1; //逆时针 if(chaji(p1,p2)<0) return 2; //顺时针 if(dot(p1,p2)<0) return 3; // 两条直线共线且相反 if(p1.x*p1.x+p1.y*p1.y<p2.x*p2.x+p2.y*p2.y) return 4; //方向 p0->p1->p2 return 5; //p2在中间 }
原文地址:https://www.cnblogs.com/ww123/p/9038516.html
时间: 2024-10-04 17:17:22