給定兩組點集,判斷其凸包是否相離 (無交點、無包含)。若相離輸出 "Yes",否則 "No"。
CH1, CH2),使用 Andrew 算法。
struct Point { double x, y; };
double cross(Point a, Point b) { return a.x*b.y - a.y*b.x; }
Point operator-(Point a, Point b) { return {a.x-b.x, a.y-b.y}; }
bool onSegment(Point p, Point a, Point b) {
return fabs(cross(a-p, b-p)) < eps && dot(a-p, b-p) < eps;
}
bool segIntersect(Point a1, Point a2, Point b1, Point b2) {
double c1=cross(a2-a1,b1-a1), c2=cross(a2-a1,b2-a1);
double c3=cross(b2-b1,a1-b1), c4=cross(b2-b1,a2-b1);
return sgn(c1)*sgn(c2)<0 && sgn(c3)*sgn(c4)<0; // 真相交
}
int pointInPoly(Point p, vector& poly) {
// 射線法,返回 0=外部, 1=內部, -1=邊界
}
bool disjoint(vector& ch1, vector& ch2) {
for (auto p:ch1) if (pointInPoly(p,ch2)!=0) return false;
for (auto p:ch2) if (pointInPoly(p,ch1)!=0) return false;
for (int i=0;i
凸包 O(N log N),分離性檢查 O(|CH1| * |CH2|),總點數較小可接受。