diff options
| author | MZuenni <michi.zuendorf@gmail.com> | 2023-02-13 19:39:30 +0100 |
|---|---|---|
| committer | MZuenni <michi.zuendorf@gmail.com> | 2023-02-13 19:39:30 +0100 |
| commit | 3a98de95336d3deb5d78cafdde6cc63dc3fd5f4f (patch) | |
| tree | 30f0428accc66062a07026a2bfa15fb88647523d /geometry | |
| parent | 54946c9945857e42b8eb4025a66d3344bd53f07c (diff) | |
squezed in new code :D
Diffstat (limited to 'geometry')
| -rw-r--r-- | geometry/antipodalPoints.cpp | 9 | ||||
| -rw-r--r-- | geometry/geometry.tex | 18 | ||||
| -rw-r--r-- | geometry/linesAndSegments.cpp | 5 | ||||
| -rw-r--r-- | geometry/polygon.cpp | 8 | ||||
| -rw-r--r-- | geometry/triangle.cpp | 13 |
5 files changed, 24 insertions, 29 deletions
diff --git a/geometry/antipodalPoints.cpp b/geometry/antipodalPoints.cpp index 06efd6c..db39b39 100644 --- a/geometry/antipodalPoints.cpp +++ b/geometry/antipodalPoints.cpp @@ -1,13 +1,12 @@ vector<pair<int, int>> antipodalPoints(vector<pt>& h) { + if (sz(h) < 2) return {}; vector<pair<int, int>> result; - int n = sz(h); - if (n < 2) return result; for (int i = 0, j = 1; i < j; i++) { while (true) { result.push_back({i, j}); - if (cross(h[(i + 1) % n] - h[i], - h[(j + 1) % n] - h[j]) <= 0) break; - j = (j + 1) % n; + if (cross(h[(i + 1) % sz(h)] - h[i], + h[(j + 1) % sz(h)] - h[j]) <= 0) break; + j = (j + 1) % sz(h); }} return result; } diff --git a/geometry/geometry.tex b/geometry/geometry.tex index 3e50a8e..a027de4 100644 --- a/geometry/geometry.tex +++ b/geometry/geometry.tex @@ -7,6 +7,14 @@ \sourcecode{geometry/closestPair.cpp} \end{algorithm} +\begin{algorithm}{Rotating calipers} + \begin{methods} + \method{antipodalPoints}{berechnet antipodale Punkte}{n} + \end{methods} + \textbf{WICHTIG:} Punkte müssen gegen den Uhrzeigersinn Sortiert sein und konvexes Polygon bilden! + \sourcecode{geometry/antipodalPoints.cpp} +\end{algorithm} + \begin{algorithm}{Konvexe Hülle} \begin{methods} \method{convexHull}{berechnet Konvexehülle}{n\*\log(n)} @@ -19,22 +27,14 @@ \sourcecode{geometry/convexHull.cpp} \end{algorithm} -\begin{algorithm}{Rotating calipers} - \begin{methods} - \method{antipodalPoints}{berechnet antipodale Punkte}{n} - \end{methods} - \textbf{WICHTIG:} Punkte müssen gegen den Uhrzeigersinn Sortiert sein und konvexes Polygon bilden! - \sourcecode{geometry/antipodalPoints.cpp} -\end{algorithm} - \subsection{Formeln~~--~\texttt{std::complex}} \sourcecode{geometry/formulars.cpp} \sourcecode{geometry/linesAndSegments.cpp} \input{geometry/triangle} \sourcecode{geometry/triangle.cpp} \sourcecode{geometry/polygon.cpp} -\sourcecode{geometry/circle.cpp} \sourcecode{geometry/sortAround.cpp} +\sourcecode{geometry/circle.cpp} \subsection{Formeln - 3D} \sourcecode{geometry/formulars3d.cpp} diff --git a/geometry/linesAndSegments.cpp b/geometry/linesAndSegments.cpp index a9ba9ab..d298fde 100644 --- a/geometry/linesAndSegments.cpp +++ b/geometry/linesAndSegments.cpp @@ -82,9 +82,8 @@ double distBetweenSegments(pt a, pt b, pt c, pt d) { distToSegment(c, d, a), distToSegment(c, d, b)}); } -// sortiert alle Punkte pts auf einer Linie -// entsprechend der richtung dir 2d und 3d -void sortLine(pt dir, vector<pt>& pts) { +// sortiert alle Punkte pts auf einer Linie entsprechend dir +void sortLine(pt dir, vector<pt>& pts) { // (2d und 3d) sort(all(pts), [&](pt a, pt b){ return dot(dir, a) < dot(dir, b); }); diff --git a/geometry/polygon.cpp b/geometry/polygon.cpp index 1620d7c..8b943a6 100644 --- a/geometry/polygon.cpp +++ b/geometry/polygon.cpp @@ -123,7 +123,6 @@ int extremal(const vector<pt>& hull, pt dir) { vector<int> intersect(const vector<pt>& hull, pt a, pt b) { int endA = extremal(hull, (a-b) * pt(0, 1)); int endB = extremal(hull, (b-a) * pt(0, 1)); - // cross == 0 => line only intersects border if (cross(hull[endA], a, b) > 0 || cross(hull[endB], a, b) < 0) return {}; @@ -136,11 +135,10 @@ vector<int> intersect(const vector<pt>& hull, pt a, pt b) { while (l + 1 < r) { int m = (l + r) / 2; if (cross(hull[m % n], a, b) <= 0 && - cross(hull[m % n], a, b) != hull(poly[endB], a, b)) { + cross(hull[m % n], a, b) != hull(poly[endB], a, b)) l = m; - } else { - r = m; - }} + else r = m; + } if (cross(hull[r % n], a, b) == 0) l++; res.push_back(l % n); swap(endA, endB); diff --git a/geometry/triangle.cpp b/geometry/triangle.cpp index 4dbd532..a00eb56 100644 --- a/geometry/triangle.cpp +++ b/geometry/triangle.cpp @@ -12,6 +12,12 @@ double area(double a, double b, double c) { return sqrt(s * (s-a) * (s-b) * (s-c)); } +// Zentrum des größten Kreises im Dreiecke +pt inCenter(pt a, pt b, pt c) { + double x = abs(a-b), y = abs(b-c), z = abs(a-c); + return (y*a + z*b + x*c) / (x+y+z); +} + // Zentrum des Kreises durch alle Eckpunkte pt outCenter(pt a, pt b, pt c) { double d = 2.0 * (real(a) * imag(b-c) + @@ -22,13 +28,6 @@ pt outCenter(pt a, pt b, pt c) { c*conj(c)*conj(a-b)) / d; } -// Zentrum des größten Kreises im Dreiecke -pt inCenter(pt a, pt b, pt c) { - double x = abs(a-b), y = abs(b-c), z = abs(a-c); - return (y*a + z*b + x*c) / (x+y+z); -} - - // Sind die Dreiecke a1, b1, c1, and a2, b2, c2 ähnlich? // Erste Zeile testet Ähnlichkeit mit gleicher Orientierung, // zweite Zeile testet Ähnlichkeit mit verschiedener Orientierung |
