Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int fEqual(double a, double b) {
- return (fabs(a - b) < eps) ? 1 : 0;
- }
- bool CW(point a, point b, point c) { // Cùng chiều kim đồng hồ
- return a.x*(c.y-b.y) + b.x*(a.y-c.y) + c.x*(b.y-a.y) > 0;
- }
- bool CCW(point a, point b, point c) { // Ngược chiều kim đồng hồ
- return a.x*(c.y-b.y) + b.x*(a.y-c.y) + c.x*(b.y-a.y) < 0;
- }
- bool check(point &p) {
- if (hull.size() < 3)
- return false;
- int l = 1, r = hull.size() - 1;
- if (CCW(hull[0], hull[l], hull[r]))
- swap(l, r);
- if (CCW(hull[0], hull[l], p) || CW(hull[0], hull[r], p))
- return false;
- while (abs(r - l) > 1) {
- int m = (l + r) / 2;
- if (CW(hull[0], hull[m], p))
- l = m;
- else
- r = m;
- }
- if (CCW(hull[l], hull[r], p)) return false;
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment