From 9e49119508787d618d6002526902cb6fa4e01f35 Mon Sep 17 00:00:00 2001 From: Noobie99 Date: Tue, 16 May 2023 12:05:07 +0200 Subject: fixed inside convex and minkowski --- geometry/polygon.cpp | 18 +++++++++--------- tcr.pdf | Bin 652065 -> 669186 bytes 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/geometry/polygon.cpp b/geometry/polygon.cpp index 409f765..6738ab2 100644 --- a/geometry/polygon.cpp +++ b/geometry/polygon.cpp @@ -38,17 +38,17 @@ bool inside(pt p, const vector& poly) { return in; } -// convex hull without duplicates, h[0] == h.back() -// Change line 45 and 51 >= if border counts as inside +// convex hull without duplicates, h[0] != h.back() +// apply comments if border counts as inside bool inside(pt p, const vector& hull) { int l = 0, r = sz(hull) - 1; - if (cross(hull[0], hull[r], p) > 0) return false; + if (cross(hull[0], hull[r], p) >= 0) return false; // > 0 while (l + 1 < r) { int m = (l + r) / 2; - if (cross(hull[0], hull[m], p) >= 0) l = m; + if (cross(hull[0], hull[m], p) > 0) l = m; // >= 0 else r = m; } - return cross(hull[l], hull[r], p) > 0; + return cross(hull[l], hull[r], p) > 0; // >= 0 } void rotateMin(vector& hull) { @@ -71,8 +71,8 @@ vector minkowski(vector ps, vector qs) { for (ll i = 0, j = 0; i + 2 < sz(ps) || j + 2 < sz(qs);) { res.push_back(ps[i] + qs[j]); auto c = cross(ps[i + 1] - ps[i], qs[j + 1] - qs[j]); - if(c <= 0) i++; - if(c >= 0) j++; + if(c >= 0) i++; + if(c <= 0) j++; } return res; } @@ -94,7 +94,7 @@ double dist(const vector& ps, const vector& qs) { bool left(pt of, pt p) {return cross(p, of) < 0 || (cross(p, of) == 0 && dot(p, of) > 0);} -// convex hulls without duplicates, hull[0] == hull.back() and +// convex hulls without duplicates, hull[0] != hull.back() and // hull[0] must be a convex point (with angle < pi) // returns index of corner where dot(dir, corner) is maximized int extremal(const vector& hull, pt dir) { @@ -114,7 +114,7 @@ int extremal(const vector& hull, pt dir) { return r; } -// convex hulls without duplicates, hull[0] == hull.back() and +// convex hulls without duplicates, hull[0] != hull.back() and // hull[0] must be a convex point (with angle < pi) // {} if no intersection // {x} if corner is only intersection diff --git a/tcr.pdf b/tcr.pdf index 166de4d..d42fa86 100644 Binary files a/tcr.pdf and b/tcr.pdf differ -- cgit v1.2.3