14 #if !defined(QUATERNION_H_INCLUDED)
15 #define QUATERNION_H_INCLUDED
84 mQuaternionValues=other.mQuaternionValues;
90 return mQuaternionValues[
i];
94 return mQuaternionValues[
i];
121 inline const T
X()
const {
return mQuaternionValues[0]; }
122 inline void SetX(
const T& value) { mQuaternionValues[0] = value; }
129 inline const T
Y()
const {
return mQuaternionValues[1]; }
130 inline void SetY(
const T& value) { mQuaternionValues[1] = value; }
137 inline const T
Z()
const {
return mQuaternionValues[2]; }
138 inline void SetZ(
const T& value) { mQuaternionValues[2] = value; }
145 inline const T
W()
const {
return mQuaternionValues[3]; }
146 inline void SetW(
const T& value) { mQuaternionValues[3] = value; }
162 return X()*
X() +
Y()*
Y() +
Z()*
Z() +
W()*
W();
182 if(n > 0.0 &&
n != 1.0) {
184 mQuaternionValues[0] /=
n;
185 mQuaternionValues[1] /=
n;
186 mQuaternionValues[2] /=
n;
187 mQuaternionValues[3] /=
n;
212 template<
class TMatrix3x3>
215 if(
R.size1()!=3 ||
R.size2()!=3 )
218 R(0, 0) = 2.0 * (
W()*
W() +
X()*
X() - 0.5 );
219 R(0, 1) = 2.0 * (
X()*
Y() -
W()*
Z() );
220 R(0, 2) = 2.0 * (
X()*
Z() +
W()*
Y() );
222 R(1, 0) = 2.0 * (
Y()*
X() +
W()*
Z() );
223 R(1, 1) = 2.0 * (
W()*
W() +
Y()*
Y() - 0.5 );
224 R(1, 2) = 2.0 * (
Y()*
Z() -
X()*
W() );
226 R(2, 0) = 2.0 * (
Z()*
X() -
W()*
Y() );
227 R(2, 1) = 2.0 * (
Z()*
Y() +
W()*
X() );
228 R(2, 2) = 2.0 * (
W()*
W() +
Z()*
Z() - 0.5 );
238 double test =
W() *
W() -
X() *
X() -
Y() *
Y() +
Z() *
Z();
239 if (
test > (1.0 - 1.0e-6)) {
240 EA[0] = -atan2 (2 *
Z() *
W(), (
W() *
W() -
Z() *
Z()));
244 else if (
test < (-1.0 + 1.0e-6)) {
245 EA[0] = atan2 (2 *
Z() *
W(), (
W() *
W() -
Z() *
Z()));
250 EA[0] = atan2((
X() *
Z() +
Y() *
W()), -(
Y() *
Z() -
X() *
W()));
251 EA[1] = -acos (
test);
252 EA[2] = atan2((
X() *
Z() -
Y() *
W()), (
Y() *
Z() +
X() *
W()));
279 T vNorm = xx*xx + yy*yy + zz*zz;
288 vNorm = std::sqrt(vNorm);
290 T
mult = (vNorm < ww) ? (2.0 / vNorm * std::asin(vNorm)) : (2.0 / vNorm * std::acos(ww));
305 template<
class TVector3>
324 template<
class TVector3_A,
class TVector3_B>
328 b(0) = 2.0 * (
Y() *
a(2) -
Z() *
a(1));
329 b(1) = 2.0 * (
Z() *
a(0) -
X() *
a(2));
330 b(2) = 2.0 * (
X() *
a(1) -
Y() *
a(0));
333 T c0 =
Y() *
b(2) -
Z() *
b(1);
334 T c1 =
Z() *
b(0) -
X() *
b(2);
335 T c2 =
X() *
b(1) -
Y() *
b(0);
338 b(0) =
a(0) +
b(0)*
W() + c0;
339 b(1) =
a(1) +
b(1)*
W() + c1;
340 b(2) =
a(2) +
b(2)*
W() + c2;
353 template<
class TVector3>
357 T b0 = 2.0 * (
Y() *
a(2) -
Z() *
a(1));
358 T b1 = 2.0 * (
Z() *
a(0) -
X() *
a(2));
359 T b2 = 2.0 * (
X() *
a(1) -
Y() *
a(0));
362 T c0 =
Y() * b2 -
Z() * b1;
363 T c1 =
Z() * b0 -
X() * b2;
364 T c2 =
X() * b1 -
Y() * b0;
398 T sqnorm =
x*
x +
y*
y +
z*
z;
403 T
norm = std::sqrt(sqnorm);
409 T halfAngle = radians * 0.5;
411 T s = std::sin(halfAngle);
412 T q0 = std::cos(halfAngle);
429 T rModulus = rx*rx + ry*ry + rz*rz;
433 if(rModulus != 1.0) {
434 rModulus = std::sqrt(rModulus);
440 T halfAngle = rModulus * 0.5;
442 T q0 = std::cos(halfAngle);
443 T s = std::sin(halfAngle);
457 template<
class TVector3>
474 template<
class TMatrix3x3>
482 if ((tr > xx) && (tr > yy) && (tr > zz))
484 T
S = std::sqrt(tr + 1.0) * 2.0;
487 (
m(2, 1) -
m(1, 2)) /
S,
488 (
m(0, 2) -
m(2, 0)) /
S,
489 (
m(1, 0) -
m(0, 1)) /
S
492 else if ((xx > yy) && (xx > zz))
494 T
S = std::sqrt(1.0 + xx - yy - zz) * 2.0;
496 (
m(2, 1) -
m(1, 2)) /
S,
498 (
m(0, 1) +
m(1, 0)) /
S,
499 (
m(0, 2) +
m(2, 0)) /
S
504 T
S = std::sqrt(1.0 + yy - xx - zz) * 2.0;
506 (
m(0, 2) -
m(2, 0)) /
S,
507 (
m(0, 1) +
m(1, 0)) /
S,
509 (
m(1, 2) +
m(2, 1)) /
S
514 T
S = std::sqrt(1.0 + zz - xx - yy) * 2.0;
516 (
m(1, 0) -
m(0, 1)) /
S,
517 (
m(0, 2) +
m(2, 0)) /
S,
518 (
m(1, 2) +
m(2, 1)) /
S,
537 double c2 = cos(-EA[1]/2);
double c1p3 = cos((EA[0]+EA[2])/2);
double c1m3 = cos((EA[0]-EA[2])/2);
538 double s2 = sin(-EA[1]/2);
double s1p3 = sin((EA[0]+EA[2])/2);
double s1m3 = sin((EA[0]-EA[2])/2);
556 rOStream << std::endl << this->
X() <<
" " << this->
Y() <<
" " << this->
Z() <<
" " <<this->
W()<< std::endl;
575 rSerializer.
save(
"mQuaternionValues", mQuaternionValues);
580 rSerializer.
load(
"mQuaternionValues", mQuaternionValues);
583 virtual std::string
Info()
const {
584 std::stringstream buffer;
585 buffer <<
"Quaternion " ;
602 a.W() *
b.W() -
a.X() *
b.X() -
a.Y() *
b.Y() -
a.Z() *
b.Z(),
603 a.W() *
b.X() +
a.X() *
b.W() +
a.Y() *
b.Z() -
a.Z() *
b.Y(),
604 a.W() *
b.Y() +
a.Y() *
b.W() +
a.Z() *
b.X() -
a.X() *
b.Z(),
605 a.W() *
b.Z() +
a.Z() *
b.W() +
a.X() *
b.Y() -
a.Y() *
b.X()
std::string Info() const override
Turn back information as a string.
Definition: periodic_interface_process.hpp:93
Quaternion A simple class that implements the main features of quaternion algebra.
Definition: quaternion.h:28
KRATOS_DEPRECATED_MESSAGE("Deprecated method due to style") inline const T x() const
Definition: quaternion.h:120
void SetX(const T &value)
Definition: quaternion.h:122
T value_type
Definition: quaternion.h:34
static Quaternion Identity()
Definition: quaternion.h:383
const T norm() const
Definition: quaternion.h:170
void SetZ(const T &value)
Definition: quaternion.h:138
static Quaternion FromRotationMatrix(const TMatrix3x3 &m)
Definition: quaternion.h:475
void ToRotationVector(TVector3 &v) const
Definition: quaternion.h:306
static Quaternion FromRotationVector(const TVector3 &v)
Definition: quaternion.h:458
void normalize()
Definition: quaternion.h:179
Quaternion()
Definition: quaternion.h:44
void SetW(const T &value)
Definition: quaternion.h:146
void ToRotationMatrix(TMatrix3x3 &R) const
Definition: quaternion.h:213
Quaternion(T w, T x, T y, T z)
Definition: quaternion.h:54
KRATOS_DEPRECATED_MESSAGE("Deprecated method due to style") inline const T w() const
Definition: quaternion.h:144
const T W() const
Definition: quaternion.h:145
void SetY(const T &value)
Definition: quaternion.h:130
static Quaternion FromEulerAngles(const array_1d< double, 3 > &EA)
Definition: quaternion.h:534
KRATOS_CLASS_POINTER_DEFINITION(Quaternion)
KRATOS_DEPRECATED_MESSAGE("Deprecated method due to style") inline const T z() const
Definition: quaternion.h:136
Quaternion & operator=(const Quaternion &other)
Definition: quaternion.h:82
const T Y() const
Definition: quaternion.h:129
Quaternion(const Quaternion &other)
Definition: quaternion.h:65
void ToRotationVector(T &rx, T &ry, T &rz) const
Definition: quaternion.h:262
void ToEulerAngles(array_1d< double, 3 > &EA) const
Definition: quaternion.h:236
void RotateVector3(const TVector3_A &a, TVector3_B &b) const
Definition: quaternion.h:325
value_type const & const_reference
Definition: quaternion.h:36
virtual ~Quaternion()
Destructor.
Definition: quaternion.h:71
const T X() const
Definition: quaternion.h:121
const_reference operator[](size_t i) const
Definition: quaternion.h:89
const T Z() const
Definition: quaternion.h:137
void RotateVector3(TVector3 &a) const
Definition: quaternion.h:354
virtual void PrintInfo(std::ostream &rOStream) const
Definition: quaternion.h:550
value_type & reference
Definition: quaternion.h:35
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: quaternion.h:555
KRATOS_DEPRECATED_MESSAGE("Deprecated method due to style") inline const T y() const
Definition: quaternion.h:128
const T squaredNorm() const
Definition: quaternion.h:160
static Quaternion FromRotationVector(T rx, T ry, T rz)
Definition: quaternion.h:427
static Quaternion FromAxisAngle(T x, T y, T z, T radians)
Definition: quaternion.h:396
Quaternion conjugate() const
Definition: quaternion.h:195
The serialization consists in storing the state of an object into a storage format like data file or ...
Definition: serializer.h:123
void load(std::string const &rTag, TDataType &rObject)
Definition: serializer.h:207
void save(std::string const &rTag, std::array< TDataType, TDataSize > const &rObject)
Definition: serializer.h:545
z
Definition: GenerateWind.py:163
constexpr double Pi
Definition: global_variables.h:25
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
Expression::Pointer operator*(const Expression::ConstPointer &rpLeft, const double Right)
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
y
Other simbols definition.
Definition: generate_axisymmetric_navier_stokes_element.py:54
v
Definition: generate_convection_diffusion_explicit_element.py:114
w
Definition: generate_convection_diffusion_explicit_element.py:108
a
Definition: generate_stokes_twofluid_element.py:77
S
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:39
b
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:31
R
Definition: isotropic_damage_automatic_differentiation.py:172
tuple Q
Definition: isotropic_damage_automatic_differentiation.py:235
def load(f)
Definition: ode_solve.py:307
tuple const
Definition: ode_solve.py:403
def mult(A, x)
Definition: ode_solve.py:320
int n
manufactured solution and derivatives (u=0 at z=0 dudz=0 at z=domain_height)
Definition: ode_solve.py:402
test
Definition: run_make_mesh_ethier_benchmark.py:26
int m
Definition: run_marine_rain_substepping.py:8
x
Definition: sensitivityMatrix.py:49
integer i
Definition: TensorModule.f:17