YAP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Rotation.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_Rotation_h
22 #define yap_Rotation_h
23 
24 #include "Matrix.h"
25 #include "ThreeVector.h"
26 
27 namespace yap {
28 
32 template <typename T>
33 const ThreeMatrix<T> rotation(const ThreeVector<T>& V, const T& theta)
34 {
35  T v = abs(V);
36 
37  if (v == 0 || theta == 0)
38  return unitMatrix<T, 3>();
39 
40  // normalize direction vector
41  ThreeVector<T> U = V * (T(1) / v);
42 
43  T cosTheta = cos(theta);
44 
45  return ((T)1 - cosTheta) * outer(U, U) + cosTheta * unitMatrix<T, 3>() + (T)sin(theta) * skewSymmetric(U);
46 }
47 
55 template <typename T>
56 const ThreeMatrix<T> eulerRotationZXZ(const CoordinateSystem<T, 3>& C, const T& alpha, const T& beta, const T& gamma)
57 { return rotation(C[2], gamma) * rotation(C[0], beta) * rotation(C[2], alpha); }
58 
66 template <typename T>
67 const ThreeMatrix<T> eulerRotationZYZ(const CoordinateSystem<T, 3>& C, const T& alpha, const T& beta, const T& gamma)
68 { return rotation(C[2], gamma) * rotation(C[1], beta) * rotation(C[2], alpha); }
69 
70 }
71 #endif
const ThreeMatrix< T > rotation(const ThreeVector< T > &V, const T &theta)
Definition: Rotation.h:33
const ThreeMatrix< T > eulerRotationZYZ(const CoordinateSystem< T, 3 > &C, const T &alpha, const T &beta, const T &gamma)
Definition: Rotation.h:67
constexpr T theta(const ThreeVector< T > &V, const CoordinateSystem< T, 3 > &C)
Definition: CoordinateSystem.h:101
constexpr T abs(const Vector< T, N > &A)
Definition: Vector.h:371
constexpr SquareMatrix< T, 3 > skewSymmetric(const ThreeVector< T > V) noexcept
skew symmetric matrix formed from a 3 vector
Definition: ThreeVector.h:38
const ThreeMatrix< T > eulerRotationZXZ(const CoordinateSystem< T, 3 > &C, const T &alpha, const T &beta, const T &gamma)
Definition: Rotation.h:56
const SquareMatrix< T, N > outer(const Vector< T, N > &A, const Vector< T, N > &B)
outer product
Definition: Vector.h:405