OPAL (Object Oriented Parallel Accelerator Library) 2022.1
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
7template <class, unsigned>
8class Tenzor;
9
10class Quaternion: public Vektor<double, 4> {
11public:
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
49inline
51 Vektor<double, 4>(1.0, 0.0, 0.0, 0.0)
52{}
53
54inline
56 Vektor<double, 4>(quat)
57{}
58
59inline
60Quaternion::Quaternion(const double & x0, const double & x1, const double & x2, const double & x3):
61 Vektor<double, 4>(x0, x1, x2, x3)
62{}
63
64inline
66 Quaternion(0.0, vec(0), vec(1), vec(2))
67{}
68
69inline
70Quaternion::Quaternion(const double & realPart, const Vector_t & vec):
71 Quaternion(realPart, vec(0), vec(1), vec(2))
72{}
73
74inline
75double Quaternion::Norm() const
76{
77 return dot(*this, *this);
78}
79
80inline
81double Quaternion::length() const
82{
83 return std::sqrt(this->Norm());
84}
85
86inline
88{
89 return (std::abs(this->Norm() - 1.0) < 1e-12);
90}
91
92inline
94{
95 return (std::abs((*this)(0)) < 1e-12);
96}
97
98inline
100{
101 return (this->isPure() && this->isUnit());
102}
103
104inline
106{
107 Quaternion quat(this->real(), -this->imag());
108
109 return quat;
110}
111
112inline
113double Quaternion::real() const
114{
115 return (*this)(0);
116}
117
118inline
120{
121 Vector_t vec((*this)(1), (*this)(2), (*this)(3));
122
123 return vec;
124}
125
126
127#endif
double dot(const Vector3D &lhs, const Vector3D &rhs)
Vector dot product.
Definition: Vector3D.cpp:118
Quaternion Quaternion_t
Definition: Quaternion.h:44
Quaternion getQuaternion(Vector_t vec, Vector_t reference)
Definition: Quaternion.cpp:34
Tps< T > sqrt(const Tps< T > &x)
Square root.
Definition: TpsMath.h:91
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 Quaternion &)=default
Quaternion operator*(const double &) const
Definition: Quaternion.cpp:71
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