diff options
| author | kittobi1992 <kittobi1992@users.noreply.github.com> | 2014-11-22 16:57:15 +0100 |
|---|---|---|
| committer | kittobi1992 <kittobi1992@users.noreply.github.com> | 2014-11-22 16:57:15 +0100 |
| commit | 21d8d8f405048b1d9e4597f0f6fabc45ffdff20f (patch) | |
| tree | 7d5156eb647102aa395b13d32d5bd39642f059c5 /geometry | |
| parent | bb5ed48ce293212affa6c911d88220260f413189 (diff) | |
wrong
Diffstat (limited to 'geometry')
| -rw-r--r-- | geometry/convexHull | 49 |
1 files changed, 0 insertions, 49 deletions
diff --git a/geometry/convexHull b/geometry/convexHull deleted file mode 100644 index 5d6bc16..0000000 --- a/geometry/convexHull +++ /dev/null @@ -1,49 +0,0 @@ -#include <algorithm> -#include <iostream> -#include <sstream> -#include <string> -#include <vector> -using namespace std; - -struct point { - double x, y; - point(){} point(double x, double y) : x(x), y(y) {} - bool operator <(const point &p) const { - return x < p.x || (x == p.x && y < p.y); - } -}; - -// 2D cross product. -// Return a positive value, if OAB makes a counter-clockwise turn, -// negative for clockwise turn, and zero if the points are collinear. -double cross(const point &O, const point &A, const point &B){ - double d = (A.x - O.x) * (B.y - O.y) - (A.y - O.y) * (B.x - O.x); - if (fabs(d) < 1e-9) return 0.0; - return d; -} - -// Returns a list of points on the convex hull in counter-clockwise order. -// Colinear points are not in the convex hull, if you want colinear points in the hull remove "=" in the CCW-Test -// Note: the last point in the returned list is the same as the first one. -vector<point> convexHull(vector<point> P){ - int n = P.size(), k = 0; - vector<point> H(2*n); - - // Sort points lexicographically - sort(P.begin(), P.end()); - - // Build lower hull - for (int i = 0; i < n; i++) { - while (k >= 2 && cross(H[k-2], H[k-1], P[i]) <= 0.0) k--; - H[k++] = P[i]; - } - - // Build upper hull - for (int i = n-2, t = k+1; i >= 0; i--) { - while (k >= t && cross(H[k-2], H[k-1], P[i]) <= 0.0) k--; - H[k++] = P[i]; - } - - H.resize(k); - return H; -} |
