summaryrefslogtreecommitdiff
path: root/math
diff options
context:
space:
mode:
authorPaul Jungeblut <paul.jungeblut@gmail.com>2016-04-24 10:46:02 +0200
committerPaul Jungeblut <paul.jungeblut@gmail.com>2016-04-24 10:46:02 +0200
commit86978d60f8d2148362119fdccf680320a50dcc1f (patch)
tree087bd1b1f94f14d520808d634cee4ae28af81360 /math
parent71963a0e396b6781d39bf9c3dfe2e76e44d9f5a2 (diff)
Adding 3D spheres and some small changes to KMP.
Diffstat (limited to 'math')
-rw-r--r--math/gcDist.cpp23
-rw-r--r--math/math.tex5
2 files changed, 27 insertions, 1 deletions
diff --git a/math/gcDist.cpp b/math/gcDist.cpp
new file mode 100644
index 0000000..d661744
--- /dev/null
+++ b/math/gcDist.cpp
@@ -0,0 +1,23 @@
+// Great Cirlce Distance mit Längen- und Breitengrad.
+double gcDist(double pLat, double pLon, double qLat, double qLon, double radius) {
+ pLat *= PI / 180; pLon *= PI / 180; qLat *= PI / 180; qLon *= PI / 180;
+ return radius * acos(cos(pLat) * cos(pLon) * cos(qLat) * cos(qLon) +
+ cos(pLat) * sin(pLon) * cos(qLat) * sin(qLon) +
+ sin(pLat) * sin(qLat));
+}
+
+// Great Cirlce Distance mit kartesischen Koordinaten.
+double gcDist(point p, point q) {
+ return acos(p.x * q.x + p.y * q.y + p.z * q.z);
+}
+
+// 3D Punkt in kartesischen Koordinaten.
+struct point{
+ double x, y, z;
+ point() {}
+ point(double x, double y, double z) : x(x), y(y), z(z) {}
+ point(double lat, double lon) {
+ lat *= PI / 180.0; lon *= PI / 180.0;
+ x = cos(lat) * sin(lon); y = cos(lat) * cos(lon); z = sin(lat);
+ }
+};
diff --git a/math/math.tex b/math/math.tex
index 51410bd..90e7b3b 100644
--- a/math/math.tex
+++ b/math/math.tex
@@ -176,4 +176,7 @@ Anzahl der Teilmengen von $\mathbb{N}$, die sich zu $n$ aufaddieren mit maximale
\#labeled rooted trees & $n^{n-1}$\\
\#labeled unrooted trees & $n^{n-2}$\\
\hline
-\end{tabular} \ No newline at end of file
+\end{tabular}
+
+\subsection{3D-Kugeln}
+\lstinputlisting{math/gcDist.cpp}