Convex Hull
unknown
c_cpp
3 years ago
497 B
4
Indexable
Never
vector<Point> convex_hull(vector<Point> P) { int n = P.size(), k = 0; vector<Point> H(2*n); sort(P.begin(), P.end()); for (int i = 0; i < n; ++i) { while (k >= 2 && cross(H[k-2], H[k-1], P[i]) < 0) k--; H[k++] = P[i]; } for (int i = n-2, t = k+1; i >= 0; i--) { while (k >= t && cross(H[k-2], H[k-1], P[i]) < 0) k--; H[k++] = P[i]; } H.resize(k); return H; } double dist( Point a , Point b ) { return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)) ; }