YAP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CoordinateSystem.h
Go to the documentation of this file.
1 /* YAP - Yet another PWA toolkit
2  Copyright 2015, Technische Universitaet Muenchen,
3  Authors: Daniel Greenwald, Johannes Rauch
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
20 
21 #ifndef yap_CoordinateSystem_h
22 #define yap_CoordinateSystem_h
23 
24 #include "fwd/CoordinateSystem.h"
25 
26 #include "Vector.h"
27 #include "Matrix.h"
28 #include "ThreeVector.h"
29 
30 #include <algorithm>
31 #include <string>
32 #include <type_traits>
33 
34 #define VECTOREPSILON 1e-10
35 
36 namespace yap {
37 
39 template <typename T, size_t N>
40 std::string to_string(const CoordinateSystem<T, N>& C)
41 {
42  std::string s = "(";
43  std::for_each(C.begin(), C.end(), [&](const Vector<T, N>& v) {s += to_string(v) + ", ";});
44  s.erase(s.size() - 2, 2);
45  s += ")";
46  return s;
47 }
48 
51 template <typename T, size_t N>
52 const CoordinateSystem<T, N> unit(const CoordinateSystem<T, N>& C)
53 {
54  CoordinateSystem<T, N> uC;
55  std::transform(C.begin(), C.end(), uC.begin(), [](const Vector<T, N>& c) {return yap::unit<T, N>(c);});
56  return uC;
57 }
58 
61 template <typename T, size_t N>
62 const CoordinateSystem<T, N> operator*(const SquareMatrix<T, N>& M, const CoordinateSystem<T, N>& C)
63 {
64  CoordinateSystem<T, N> MC;
65  std::transform(C.begin(), C.end(), MC.begin(), [&](const Vector<T, N>& c) {return M * c; });
66  return MC;
67 }
68 
71 
74 template <typename T>
75 constexpr bool isRightHanded(const CoordinateSystem<T, 3>& C)
76 {
77  // +[2] is proportional to [0] cross [1]
78  return (norm(unit(C[2]) - unit(cross(C[0], C[1]))) < VECTOREPSILON);
79 }
80 
83 template <typename T>
84 constexpr bool isLeftHanded(const CoordinateSystem<T, 3>& C)
85 {
86  // -[2] is proportional to [0] cross [1]
87  return (norm(unit(C[2]) + unit(cross(C[0], C[1]))) < VECTOREPSILON);
88 }
89 
93 template <typename T>
94 constexpr T phi(const ThreeVector<T>& V, const CoordinateSystem<T, 3>& C)
95 { return angle(V - (V * C[2]) * C[2], C[0]) * ( ((V * C[1]) >= 0) ? T(1) : T(-1) ); }
96 
100 template <typename T>
101 constexpr T theta(const ThreeVector<T>& V, const CoordinateSystem<T, 3>& C)
102 { return angle(V, C[2]); }
103 
108 template <typename T>
109 constexpr std::array<T, 2> angles(const ThreeVector<T>& V, const CoordinateSystem<T, 3>& C)
110 { return std::array<T, 2> { phi(V, C), theta(V, C) }; }
111 
113 
114 }
115 #endif
constexpr bool isRightHanded(const CoordinateSystem< T, 3 > &C)
Definition: CoordinateSystem.h:75
constexpr std::array< T, 2 > angles(const ThreeVector< T > &V, const CoordinateSystem< T, 3 > &C)
Definition: CoordinateSystem.h:109
constexpr T theta(const ThreeVector< T > &V, const CoordinateSystem< T, 3 > &C)
Definition: CoordinateSystem.h:101
constexpr bool isLeftHanded(const CoordinateSystem< T, 3 > &C)
Definition: CoordinateSystem.h:84
const CoordinateSystem< T, N > operator*(const SquareMatrix< T, N > &M, const CoordinateSystem< T, N > &C)
Definition: CoordinateSystem.h:62
const CoordinateSystem< T, N > unit(const CoordinateSystem< T, N > &C)
Definition: CoordinateSystem.h:52
std::string to_string(const CachedValue::Status &S)
streaming operator for CachedValue::Status
Definition: CachedValue.cxx:27
constexpr T phi(const ThreeVector< T > &V, const CoordinateSystem< T, 3 > &C)
Definition: CoordinateSystem.h:94
constexpr ThreeVector< T > cross(const ThreeVector< T > &A, const ThreeVector< T > &B) noexcept
Definition: ThreeVector.h:33
N-dimensional column vector.
Definition: Vector.h:168