From 1d2d2541dd913892a983da13f84c33f1a5d43ff6 Mon Sep 17 00:00:00 2001 From: Paul Jungeblut Date: Tue, 11 Nov 2014 15:25:06 +0100 Subject: geometrische Formeln --- geometry/formulars.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ geometry/geometry.tex | 7 ++++-- graph/graph.tex | 2 +- math/binomial.cpp | 14 +++--------- math/math.tex | 4 ++++ tcr.pdf | Bin 117854 -> 220754 bytes tcr.tex | 1 + 7 files changed, 72 insertions(+), 14 deletions(-) create mode 100644 geometry/formulars.cpp create mode 100644 math/math.tex diff --git a/geometry/formulars.cpp b/geometry/formulars.cpp new file mode 100644 index 0000000..6984be9 --- /dev/null +++ b/geometry/formulars.cpp @@ -0,0 +1,58 @@ +//komplexe Zahlen als Darstellung fuer Punkte +typedef pt complex; +//Winkel zwischen Punkt und x-Achse in [0, 2 * PI), Winkel zwischen a und b +double angle = arg (a), angle_a_b = arg (a - b); +//Punkt rotiert um Winkel theta +pt a_rotated = a * exp (pt (0, theta)); +//Mittelpunkt des Dreiecks abc +pt centroid = (a + b + c) / 3; +//Skalarprodukt +double dot(pt a, pt b) { + return real(conj(a) * b); +} +//Kreuzprodukt, 0, falls kollinear +double cross(pt a, pt b) { + return imag(conj(a) * b); +} +//wenn Eckpunkte bekannt +double areaOfTriangle(pt a, pt b, pt c) { + return abs(cross(b - a, c - a)) / 2.0; +} +//wenn Seitenlaengen bekannt +double areaOfTriangle(double a, double b, double c) { + double s = (a + b + c) / 2; + return sqrt(s * (s-a) * (s-b) * (s-c)); +} +// Sind die Dreiecke a1, b1, c1, and a2, b2, c2 aehnlich? +// Erste Zeile testet Aehnlichkeit mit gleicher Orientierung, +// zweite Zeile testst Aehnlichkeit mit unterschiedlicher Orientierung +bool similar (pt a1, pt b1, pt c1, pt a2, pt b2, pt c2) { + return ( + (b2 - a2) * (c1 - a1) == (b1 - a1) * (c2 - a2) || + (b2 - a2) * (conj (c1) - conj (a1)) == (conj (b1) - conj (a1)) * (c2 - a2) + ); +} +//Linksknick von a->b nach a->c +double ccw(pt a, pt b, pt c) { + return cross(b - a, c - a); //<0 => falls Rechtsknick, 0 => kollinear, >0 => Linksknick +} +//Streckenschnitt, Strecken a-b und c-d +bool lineSegmentIntersection(pt a, pt b, pt c, pt d) { + if (ccw(a, b, c) == 0 && ccw(a, b, d) == 0) { //kollinear + double dist = abs(a - b); + return (abs(a - c) <= dist && abs(b - c) <= dist) || (abs(a - d) <= dist && abs(b - d) <= dist); + } + return ccw(a, b, c) * ccw(a, b, d) <= 0 && ccw(c, d, a) * ccw(c, d, b) <= 0; +} +//Entfernung von p zu a-b +double distToLine(pt a, pt b, pt p) { + return abs(cross(p - a, b - a)) / abs(b - a); +} +//liegt p auf a-b +bool pointOnLine(pt a, pt b, pt p) { + return abs(distToLine(a, b, p)) < EPSILON; +} +//testet, ob d in der gleichen Ebene liegt wie a, b, und c +bool isCoplanar(pt a, pt b, pt c, pt d) { + return (b - a) * (c - a) * (d - a) == 0; +} \ No newline at end of file diff --git a/geometry/geometry.tex b/geometry/geometry.tex index 7a72526..6192c6e 100644 --- a/geometry/geometry.tex +++ b/geometry/geometry.tex @@ -1,4 +1,7 @@ -\section{Geometry} +\section{Geometrie} \subsection{Closest Pair} -\lstinputlisting{geometry/closestPair.cpp} \ No newline at end of file +\lstinputlisting{geometry/closestPair.cpp} + +\subsection{Formeln - \lstinline{std::complex}} +\lstinputlisting{geometry/formulars.cpp} \ No newline at end of file diff --git a/graph/graph.tex b/graph/graph.tex index 1c37bc7..53cfb2a 100644 --- a/graph/graph.tex +++ b/graph/graph.tex @@ -1,4 +1,4 @@ -\section{Graph} +\section{Graphen} \subsection{Strongly Connected Components (\textsc{Tarjans}-Algorithmus)} \lstinputlisting{graph/scc.cpp} diff --git a/math/binomial.cpp b/math/binomial.cpp index afc9800..61d9d69 100644 --- a/math/binomial.cpp +++ b/math/binomial.cpp @@ -1,15 +1,7 @@ -#include - -using namespace std; - - -unsigned long long calc_binom(unsigned long long N, unsigned long long K) -{ - unsigned long long r = 1; - unsigned long long d; +ll calc_binom(ll N, ll K) { + ll r = 1, d; if (K > N) return 0; - for (d = 1; d <= K; d++) - { + for (d = 1; d <= K; d++) { r *= N--; r /= d; } diff --git a/math/math.tex b/math/math.tex new file mode 100644 index 0000000..e1e0950 --- /dev/null +++ b/math/math.tex @@ -0,0 +1,4 @@ +\section{Mathe} + +\subsection{Binomialkoeffizienten} +\lstinputlisting{math/binomial.cpp} \ No newline at end of file diff --git a/tcr.pdf b/tcr.pdf index e5427c3..5116dbf 100644 Binary files a/tcr.pdf and b/tcr.pdf differ diff --git a/tcr.tex b/tcr.tex index be50976..be8556d 100644 --- a/tcr.tex +++ b/tcr.tex @@ -50,6 +50,7 @@ \input{datastructures/datastructures} \input{graph/graph} \input{geometry/geometry} +\input{math/math} \input{sonstiges/sonstiges} \end{document} \ No newline at end of file -- cgit v1.2.3