summaryrefslogtreecommitdiff
path: root/geometry
diff options
context:
space:
mode:
authorMZuenni <michi.zuendorf@gmail.com>2022-11-30 13:01:17 +0100
committerMZuenni <michi.zuendorf@gmail.com>2022-11-30 13:01:17 +0100
commit909a9c42964758c1834cd9389ac2c5724c5d6d22 (patch)
treee2501a1fa8e1e3e9cede08ae275727c1a3ece62c /geometry
parent702469ce6f966270997bfe43a9fb9881df2c0ff0 (diff)
removed sphere geometry added minkowski
Diffstat (limited to 'geometry')
-rw-r--r--geometry/geometry.tex2
-rw-r--r--geometry/polygon.cpp40
2 files changed, 42 insertions, 0 deletions
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<pt>& hull) {
}
return orientation(hull[l], hull[r], p) >= 0;
}
+
+void rotateMin(vector<pt>& 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<pt> minkowski(vector<pt> ps, vector<pt> 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<pt> 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<pt>& ps, const vector<pt>& 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;
+}