From 909a9c42964758c1834cd9389ac2c5724c5d6d22 Mon Sep 17 00:00:00 2001 From: MZuenni Date: Wed, 30 Nov 2022 13:01:17 +0100 Subject: removed sphere geometry added minkowski --- geometry/geometry.tex | 2 ++ geometry/polygon.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) (limited to 'geometry') diff --git a/geometry/geometry.tex b/geometry/geometry.tex index 1201917..e52e454 100644 --- a/geometry/geometry.tex +++ b/geometry/geometry.tex @@ -38,8 +38,10 @@ \subsection{Formeln - 3D} \sourcecode{geometry/formulars3d.cpp} +\optional{ \subsection{3D-Kugeln} \sourcecode{geometry/spheres.cpp} +} \optional{ \subsection{Geraden} diff --git a/geometry/polygon.cpp b/geometry/polygon.cpp index 6a8080d..8acd591 100644 --- a/geometry/polygon.cpp +++ b/geometry/polygon.cpp @@ -31,3 +31,43 @@ bool inside(pt p, const vector& hull) { } return orientation(hull[l], hull[r], p) >= 0; } + +void rotateMin(vector& hull) { + auto mi = min_element(all(hull), [](const pt& a, const pt& b){ + return real(a) == real(b) ? imag(a) < imag(b) + : real(a) < real(b); + }); + rotate(hull.begin(), mi, hull.end()); +} + +//convex hulls without duplicates, h[0] != h.back() +vector minkowski(vector ps, vector qs) { + rotateMin(ps); + rotateMin(qs); + ps.push_back(ps[0]); + qs.push_back(qs[0]); + ps.push_back(ps[1]); + qs.push_back(qs[1]); + vector res; + 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++; + } + return res; +} + +//convex hulls without duplicates, h[0] != h.back() +double dist(const vector& ps, const vector& qs) { + for (pt& q : qs) q *= -1; + auto p = minkowski(ps, qs); + p.push_back(p[0]); + double res = 0.0; + //bool intersect = true; + for (ll i = 0; i + 1 < sz(p); i++) { + //intersect &= cross(p[i], p[i+1] - p[i]) <= 0; + res = max(res, cross(p[i], p[i+1]-p[i]) / abs(p[i+1]-p[i])); + } + return res; +} -- cgit v1.2.3