OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
Quaternion.h
Go to the documentation of this file.
1 #ifndef OPAL_QUATERNION_H
2 #define OPAL_QUATERNION_H
3 
4 #include "AppTypes/Vektor.h"
5 #include "Algorithms/Vektor.h"
6 
7 template <class, unsigned>
8 class Tenzor;
9 
10 class Quaternion: public Vektor<double, 4> {
11 public:
12  Quaternion();
13  Quaternion(const Quaternion &);
14  Quaternion(const double &, const double &, const double &, const double &);
15  Quaternion(const Vector_t &);
16  Quaternion(const double &, const Vector_t &);
18 
19  Quaternion operator*(const double &) const;
20  Quaternion operator*(const Quaternion &) const;
21  Quaternion& operator=(const Quaternion &) = default;
23  Quaternion operator/(const double &) const;
24 
25  double Norm() const;
26  double length() const;
28 
29  bool isUnit() const;
30  bool isPure() const;
31  bool isPureUnit() const;
32 
33  Quaternion inverse() const;
34  Quaternion conjugate() const;
35 
36  double real() const;
37  Vector_t imag() const;
38 
39  Vector_t rotate(const Vector_t &) const;
40 
42 };
43 
45 
47 
48 
49 inline
51  Vektor<double, 4>(1.0, 0.0, 0.0, 0.0)
52 {}
53 
54 inline
56  Vektor<double, 4>(quat)
57 {}
58 
59 inline
60 Quaternion::Quaternion(const double & x0, const double & x1, const double & x2, const double & x3):
61  Vektor<double, 4>(x0, x1, x2, x3)
62 {}
63 
64 inline
66  Quaternion(0.0, vec(0), vec(1), vec(2))
67 {}
68 
69 inline
70 Quaternion::Quaternion(const double & realPart, const Vector_t & vec):
71  Quaternion(realPart, vec(0), vec(1), vec(2))
72 {}
73 
74 inline
75 double Quaternion::Norm() const
76 {
77  return dot(*this, *this);
78 }
79 
80 inline
81 double Quaternion::length() const
82 {
83  return std::sqrt(this->Norm());
84 }
85 
86 inline
87 bool Quaternion::isUnit() const
88 {
89  return (std::abs(this->Norm() - 1.0) < 1e-12);
90 }
91 
92 inline
93 bool Quaternion::isPure() const
94 {
95  return (std::abs((*this)(0)) < 1e-12);
96 }
97 
98 inline
100 {
101  return (this->isPure() && this->isUnit());
102 }
103 
104 inline
106 {
107  Quaternion quat(this->real(), -this->imag());
108 
109  return quat;
110 }
111 
112 inline
113 double Quaternion::real() const
114 {
115  return (*this)(0);
116 }
117 
118 inline
120 {
121  Vector_t vec((*this)(1), (*this)(2), (*this)(3));
122 
123  return vec;
124 }
125 
126 
127 #endif
Tps< T > sqrt(const Tps< T > &x)
Square root.
Definition: TpsMath.h:91
Quaternion Quaternion_t
Definition: Quaternion.h:44
Quaternion getQuaternion(Vector_t vec, Vector_t reference)
Definition: Quaternion.cpp:34
double dot(const Vector3D &lhs, const Vector3D &rhs)
Vector dot product.
Definition: Vector3D.cpp:118
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
constexpr double e
The value of.
Definition: Physics.h:39
Definition: Tenzor.h:35
bool isPure() const
Definition: Quaternion.h:93
Quaternion & normalize()
Definition: Quaternion.cpp:102
Vector_t rotate(const Vector_t &) const
Definition: Quaternion.cpp:122
double real() const
Definition: Quaternion.h:113
Quaternion conjugate() const
Definition: Quaternion.h:105
Quaternion inverse() const
Definition: Quaternion.cpp:115
Tenzor< double, 3 > getRotationMatrix() const
Definition: Quaternion.cpp:135
Quaternion & operator*=(const Quaternion &)
Definition: Quaternion.cpp:84
Quaternion operator/(const double &) const
Definition: Quaternion.cpp:95
Vector_t imag() const
Definition: Quaternion.h:119
bool isUnit() const
Definition: Quaternion.h:87
Quaternion operator*(const double &) const
Definition: Quaternion.cpp:71
Quaternion & operator=(const Quaternion &)=default
bool isPureUnit() const
Definition: Quaternion.h:99
double length() const
Definition: Quaternion.h:81
double Norm() const
Definition: Quaternion.h:75
Definition: Vektor.h:32
Definition: Vec.h:22