#include struct point { int x, y; char c; }; struct line { struct point p1, p2; }; float theta(struct point p1, struct point p2) { int dx, dy, ax, ay; float t; dx = p2.x - p1.x; ax = abs(dx); dy = p2.y - p1.y; ay = abs(dy); t = (ax+ay == 0) ? 0 : (float) dy/(ax+ay); if (dx < 0) t = 2-t; else if (dy < 0) t = 4+t; return t*90.0; } int wrap(struct point p[], int N) { int i, min, M; float th, v; struct point t; for (min = 0, i = 1; i < N; i++) if (p[i].y < p[min].y) min = i; p[N] = p[min]; th = 0.0; for (M = 0; M < N; M++) { t = p[M]; p[M] = p[min]; p[min] = t; min = N; v = th; th = 360.0; for (i = M+1; i <= N; i++) if (theta(p[M], p[i]) > v) if (theta(p[M], p[i]) < th) { min = i; th = theta(p[M], p[min]); } if (min == N) return M; } return N; }