OpenMD 3.1
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
OpenMD::Quaternion< Real > Class Template Reference

Quaternion is a sort of a higher-level complex number. More...

#include "math/Quaternion.hpp"

+ Inheritance diagram for OpenMD::Quaternion< Real >:

Public Member Functions

 Quaternion (Real w, Real x, Real y, Real z)
 Constructs and initializes a Quaternion from w, x, y, z values.
 
 Quaternion (const Vector< Real, 4 > &v)
 Constructs and initializes a Quaternion from a Vector<Real,4>
 
Quaternionoperator= (const Vector< Real, 4 > &v)
 copy assignment
 
Real w () const
 Returns the value of the first element of this quaternion.
 
Real & w ()
 Returns the reference of the first element of this quaternion.
 
Real x () const
 Returns the value of the first element of this quaternion.
 
Real & x ()
 Returns the reference of the second element of this quaternion.
 
Real y () const
 Returns the value of the thirf element of this quaternion.
 
Real & y ()
 Returns the reference of the third element of this quaternion.
 
Real z () const
 Returns the value of the fourth element of this quaternion.
 
Real & z ()
 Returns the reference of the fourth element of this quaternion.
 
bool operator== (const Quaternion< Real > &q)
 Tests if this quaternion is equal to other quaternion.
 
Quaternion< Real > inverse ()
 Returns the inverse of this quaternion.
 
void mul (const Quaternion< Real > &q)
 Sets the value to the multiplication of itself and another quaternion.
 
void mul (const Real &s)
 
void div (Quaternion< Real > &q)
 Set the value of this quaternion to the division of itself by another quaternion.
 
void div (const Real &s)
 
Quaternion< Real > & operator*= (const Quaternion< Real > &q)
 
Quaternion< Real > & operator*= (const Real &s)
 
Quaternion< Real > & operator/= (Quaternion< Real > &q)
 
Quaternion< Real > & operator/= (const Real &s)
 
Quaternion< Real > conjugate () const
 Returns the conjugate quaternion of this quaternion.
 
Real get_rotation_angle () const
 return rotation angle from -PI to PI
 
Quaternion< Real > fromAxisAngle (const Vector3< Real > &axis, const Real &angle)
 create a unit quaternion from axis angle representation
 
void toAxisAngle (Vector3< Real > &axis, Real &angle) const
 convert a quaternion to axis angle representation, preserve the axis direction and angle from -PI to +PI
 
Quaternion< Real > fromShortestArc (const Vector3d &from, const Vector3d &to)
 shortest arc quaternion rotate one vector to another by shortest path.
 
Real ComputeTwist (const Quaternion &q)
 
void RemoveTwist (Quaternion &q)
 
void getTwistSwingAxisAngle (Real &twistAngle, Real &swingAngle, Vector3< Real > &swingAxis)
 
Vector3< Real > rotate (const Vector3< Real > &v)
 
Quaternion< Real > & align (const Vector3< Real > &V1, const Vector3< Real > &V2)
 
void toTwistSwing (Real &tw, Real &sx, Real &sy)
 
void toSwingTwist (Real &sx, Real &sy, Real &tw)
 
SquareMatrix< Real, 3 > toRotationMatrix3 ()
 Returns the corresponding rotation matrix (3x3)
 
- Public Member Functions inherited from OpenMD::Vector< Real, 4 >
 Vector ()
 default constructor
 
 Vector (const Vector< Real, Dim > &v)
 Constructs and initializes a Vector from a vector.
 
 Vector (const Real &s)
 
 Vector (Real *v)
 Constructs and initializes a Vector from an array.
 
Vector< Real, Dim > & operator= (const Vector< Real, Dim > &v)
 copy assignment operator
 
Vector< Real, Dim > & operator= (const Real *v)
 array assignment operator
 
Real & operator[] (unsigned int i)
 Returns reference of ith element.
 
const Real & operator[] (unsigned int i) const
 Returns constant reference of ith element.
 
Real & operator() (unsigned int i)
 Returns reference of ith element.
 
const Real & operator() (unsigned int i) const
 Returns constant reference of ith element.
 
void getArray (Real *array)
 Copy the internal data to an array.
 
Real * getArrayPointer ()
 Returns the pointer of internal array.
 
bool operator== (const Vector< Real, Dim > &v)
 Tests if this vetor is equal to other vector.
 
bool operator!= (const Vector< Real, Dim > &v)
 Tests if this vetor is not equal to other vector.
 
void zero ()
 Zeros out the values in this vector in place.
 
void negate ()
 Negates the value of this vector in place.
 
void negate (const Vector< Real, Dim > &v1)
 Sets the value of this vector to the negation of vector v1.
 
void add (const Vector< Real, Dim > &v1)
 Sets the value of this vector to the sum of itself and v1 (*this += v1).
 
void add (const Vector< Real, Dim > &v1, const Vector< Real, Dim > &v2)
 Sets the value of this vector to the sum of v1 and v2 (*this = v1 + v2).
 
void sub (const Vector< Real, Dim > &v1)
 Sets the value of this vector to the difference of itself and v1 (*this -= v1).
 
void sub (const Vector< Real, Dim > &v1, const Vector &v2)
 Sets the value of this vector to the difference of vector v1 and v2 (*this = v1 - v2).
 
void mul (Real s)
 Sets the value of this vector to the scalar multiplication of itself (*this *= s).
 
void mul (const Vector< Real, Dim > &v1, Real s)
 Sets the value of this vector to the scalar multiplication of vector v1 (*this = s * v1).
 
void Vmul (const Vector< Real, Dim > &v1, const Vector< Real, Dim > &v2)
 Sets the elements of this vector to the multiplication of elements of two other vectors.
 
Vector< Real, Dim > & abs ()
 
Real max ()
 
void div (Real s)
 Sets the value of this vector to the scalar division of itself (*this /= s ).
 
void div (const Vector< Real, Dim > &v1, Real s)
 Sets the value of this vector to the scalar division of vector v1 (*this = v1 / s ).
 
void Vdiv (const Vector< Real, Dim > &v1, const Vector< Real, Dim > &v2)
 Sets the elements of this vector to the division of elements of two other vectors.
 
Vector< Real, Dim > & operator+= (const Vector< Real, Dim > &v1)
 
Vector< Real, Dim > & operator-= (const Vector< Real, Dim > &v1)
 
Vector< Real, Dim > & operator*= (Real s)
 
Vector< Real, Dim > & operator/= (Real s)
 
Real sum ()
 Returns the sum of all elements of this vector.
 
Real componentProduct ()
 Returns the product of all elements of this vector.
 
Real length ()
 Returns the length of this vector.
 
Real lengthSquare ()
 Returns the squared length of this vector.
 
void normalize ()
 Normalizes this vector in place.
 
bool isNormalized ()
 Tests if this vector is normalized.
 
unsigned int size () const
 

Additional Inherited Members

- Public Types inherited from OpenMD::Vector< Real, 4 >
using ElemType
 
using ElemPoinerType
 
- Protected Attributes inherited from OpenMD::Vector< Real, 4 >
Real data_ [Dim]
 

Detailed Description

template<typename Real>
class OpenMD::Quaternion< Real >

Quaternion is a sort of a higher-level complex number.

It is defined as \(Q = w + x*i + y*j + z*k\), where w, x, y, and z are numbers of type T (e.g. RealType), and \(i*i = -1\); \(j*j = -1\); \(k*k = -1\); \(i*j = k\); \(j*k = i\); \(k*i = j\);

Definition at line 76 of file Quaternion.hpp.

Constructor & Destructor Documentation

◆ Quaternion() [1/3]

template<typename Real >
OpenMD::Quaternion< Real >::Quaternion ( )
inline

Definition at line 78 of file Quaternion.hpp.

◆ Quaternion() [2/3]

template<typename Real >
OpenMD::Quaternion< Real >::Quaternion ( Real w,
Real x,
Real y,
Real z )
inline

Constructs and initializes a Quaternion from w, x, y, z values.

Definition at line 81 of file Quaternion.hpp.

References OpenMD::Quaternion< Real >::w(), OpenMD::Quaternion< Real >::x(), OpenMD::Quaternion< Real >::y(), and OpenMD::Quaternion< Real >::z().

◆ Quaternion() [3/3]

template<typename Real >
OpenMD::Quaternion< Real >::Quaternion ( const Vector< Real, 4 > & v)
inline

Constructs and initializes a Quaternion from a Vector<Real,4>

Definition at line 89 of file Quaternion.hpp.

Member Function Documentation

◆ align()

template<typename Real >
Quaternion< Real > & OpenMD::Quaternion< Real >::align ( const Vector3< Real > & V1,
const Vector3< Real > & V2 )
inline

Definition at line 360 of file Quaternion.hpp.

◆ ComputeTwist()

template<typename Real >
Real OpenMD::Quaternion< Real >::ComputeTwist ( const Quaternion< Real > & q)
inline

Definition at line 312 of file Quaternion.hpp.

◆ conjugate()

template<typename Real >
Quaternion< Real > OpenMD::Quaternion< Real >::conjugate ( ) const
inline

Returns the conjugate quaternion of this quaternion.

Returns
the conjugate quaternion of this quaternion

Definition at line 236 of file Quaternion.hpp.

References OpenMD::Quaternion< Real >::w(), OpenMD::Quaternion< Real >::x(), OpenMD::Quaternion< Real >::y(), and OpenMD::Quaternion< Real >::z().

◆ div() [1/2]

template<typename Real >
void OpenMD::Quaternion< Real >::div ( const Real & s)
inline

Definition at line 206 of file Quaternion.hpp.

◆ div() [2/2]

template<typename Real >
void OpenMD::Quaternion< Real >::div ( Quaternion< Real > & q)
inline

Set the value of this quaternion to the division of itself by another quaternion.

Definition at line 204 of file Quaternion.hpp.

References OpenMD::Quaternion< Real >::inverse(), and OpenMD::Quaternion< Real >::mul().

◆ fromAxisAngle()

template<typename Real >
Quaternion< Real > OpenMD::Quaternion< Real >::fromAxisAngle ( const Vector3< Real > & axis,
const Real & angle )
inline

create a unit quaternion from axis angle representation

Definition at line 253 of file Quaternion.hpp.

References OpenMD::Vector< Real, Dim >::normalize(), OpenMD::Vector3< Real >::x(), OpenMD::Vector3< Real >::y(), and OpenMD::Vector3< Real >::z().

◆ fromShortestArc()

template<typename Real >
Quaternion< Real > OpenMD::Quaternion< Real >::fromShortestArc ( const Vector3d & from,
const Vector3d & to )
inline

shortest arc quaternion rotate one vector to another by shortest path.

create rotation from -> to, for any length vectors.

Definition at line 290 of file Quaternion.hpp.

References OpenMD::cross(), OpenMD::dot(), OpenMD::Vector< Real, 4 >::normalize(), OpenMD::Quaternion< Real >::w(), OpenMD::Vector3< Real >::x(), OpenMD::Vector3< Real >::y(), and OpenMD::Vector3< Real >::z().

◆ get_rotation_angle()

template<typename Real >
Real OpenMD::Quaternion< Real >::get_rotation_angle ( ) const
inline

◆ getTwistSwingAxisAngle()

template<typename Real >
void OpenMD::Quaternion< Real >::getTwistSwingAxisAngle ( Real & twistAngle,
Real & swingAngle,
Vector3< Real > & swingAxis )
inline

Definition at line 323 of file Quaternion.hpp.

◆ inverse()

template<typename Real >
Quaternion< Real > OpenMD::Quaternion< Real >::inverse ( )
inline

Returns the inverse of this quaternion.

Returns
inverse
Note
since quaternion is a complex number, the inverse of quaternion q = w + xi + yj+ zk is inv_q = (w -xi - yj - zk)/(|q|^2)

Definition at line 166 of file Quaternion.hpp.

References OpenMD::Vector< Real, 4 >::lengthSquare(), OpenMD::Quaternion< Real >::w(), OpenMD::Quaternion< Real >::x(), OpenMD::Quaternion< Real >::y(), and OpenMD::Quaternion< Real >::z().

Referenced by OpenMD::Quaternion< Real >::div(), OpenMD::operator/(), and OpenMD::operator/().

◆ mul() [1/2]

template<typename Real >
void OpenMD::Quaternion< Real >::mul ( const Quaternion< Real > & q)
inline

Sets the value to the multiplication of itself and another quaternion.

Parameters
qthe other quaternion

Definition at line 182 of file Quaternion.hpp.

Referenced by OpenMD::Quaternion< Real >::div(), OpenMD::operator*(), and OpenMD::operator*().

◆ mul() [2/2]

template<typename Real >
void OpenMD::Quaternion< Real >::mul ( const Real & s)
inline

Definition at line 195 of file Quaternion.hpp.

◆ operator*=() [1/2]

template<typename Real >
Quaternion< Real > & OpenMD::Quaternion< Real >::operator*= ( const Quaternion< Real > & q)
inline

Definition at line 213 of file Quaternion.hpp.

◆ operator*=() [2/2]

template<typename Real >
Quaternion< Real > & OpenMD::Quaternion< Real >::operator*= ( const Real & s)
inline

Definition at line 218 of file Quaternion.hpp.

◆ operator/=() [1/2]

template<typename Real >
Quaternion< Real > & OpenMD::Quaternion< Real >::operator/= ( const Real & s)
inline

Definition at line 228 of file Quaternion.hpp.

◆ operator/=() [2/2]

template<typename Real >
Quaternion< Real > & OpenMD::Quaternion< Real >::operator/= ( Quaternion< Real > & q)
inline

Definition at line 223 of file Quaternion.hpp.

◆ operator=()

template<typename Real >
Quaternion & OpenMD::Quaternion< Real >::operator= ( const Vector< Real, 4 > & v)
inline

copy assignment

Definition at line 92 of file Quaternion.hpp.

References OpenMD::Vector< Real, Dim >::operator=().

◆ operator==()

template<typename Real >
bool OpenMD::Quaternion< Real >::operator== ( const Quaternion< Real > & q)
inline

Tests if this quaternion is equal to other quaternion.

Returns
true if equal, otherwise return false
Parameters
qquaternion to be compared

Definition at line 152 of file Quaternion.hpp.

References OpenMD::equal().

◆ RemoveTwist()

template<typename Real >
void OpenMD::Quaternion< Real >::RemoveTwist ( Quaternion< Real > & q)
inline

Definition at line 316 of file Quaternion.hpp.

◆ rotate()

template<typename Real >
Vector3< Real > OpenMD::Quaternion< Real >::rotate ( const Vector3< Real > & v)
inline

Definition at line 347 of file Quaternion.hpp.

◆ toAxisAngle()

template<typename Real >
void OpenMD::Quaternion< Real >::toAxisAngle ( Vector3< Real > & axis,
Real & angle ) const
inline

convert a quaternion to axis angle representation, preserve the axis direction and angle from -PI to +PI

Definition at line 268 of file Quaternion.hpp.

References OpenMD::Quaternion< Real >::w(), OpenMD::Quaternion< Real >::x(), OpenMD::Vector3< Real >::x(), OpenMD::Quaternion< Real >::y(), OpenMD::Vector3< Real >::y(), OpenMD::Quaternion< Real >::z(), and OpenMD::Vector3< Real >::z().

◆ toRotationMatrix3()

template<typename Real >
SquareMatrix< Real, 3 > OpenMD::Quaternion< Real >::toRotationMatrix3 ( )
inline

◆ toSwingTwist()

template<typename Real >
void OpenMD::Quaternion< Real >::toSwingTwist ( Real & sx,
Real & sy,
Real & tw )
inline

Definition at line 482 of file Quaternion.hpp.

◆ toTwistSwing()

template<typename Real >
void OpenMD::Quaternion< Real >::toTwistSwing ( Real & tw,
Real & sx,
Real & sy )
inline

Definition at line 418 of file Quaternion.hpp.

◆ w() [1/2]

template<typename Real >
Real & OpenMD::Quaternion< Real >::w ( )
inline

Returns the reference of the first element of this quaternion.

Returns
the reference of the first element of this quaternion

Definition at line 110 of file Quaternion.hpp.

◆ w() [2/2]

◆ x() [1/2]

template<typename Real >
Real & OpenMD::Quaternion< Real >::x ( )
inline

Returns the reference of the second element of this quaternion.

Returns
the reference of the second element of this quaternion

Definition at line 122 of file Quaternion.hpp.

◆ x() [2/2]

template<typename Real >
Real OpenMD::Quaternion< Real >::x ( ) const
inline

◆ y() [1/2]

template<typename Real >
Real & OpenMD::Quaternion< Real >::y ( )
inline

Returns the reference of the third element of this quaternion.

Returns
the reference of the third element of this quaternion

Definition at line 134 of file Quaternion.hpp.

◆ y() [2/2]

template<typename Real >
Real OpenMD::Quaternion< Real >::y ( ) const
inline

◆ z() [1/2]

template<typename Real >
Real & OpenMD::Quaternion< Real >::z ( )
inline

Returns the reference of the fourth element of this quaternion.

Returns
the reference of the fourth element of this quaternion

Definition at line 145 of file Quaternion.hpp.

◆ z() [2/2]

template<typename Real >
Real OpenMD::Quaternion< Real >::z ( ) const
inline

The documentation for this class was generated from the following file: