OpenMD  2.5
Molecular Dynamics in the Open
OpenMD::Quaternion< Real > Class Template Reference

#include "math/Quaternion.hpp"

Inheritance diagram for OpenMD::Quaternion< Real >:
OpenMD::Vector< Real, 4 >

Public Member Functions

 Quaternion ()
 
 Quaternion (Real w, Real x, Real y, Real z)
 
 Quaternion (const Vector< Real, 4 > &v)
 
Quaternionoperator= (const Vector< Real, 4 > &v)
 
Real w () const
 
Real & w ()
 
Real x () const
 
Real & x ()
 
Real y () const
 
Real & y ()
 
Real z () const
 
Real & z ()
 
bool operator== (const Quaternion< Real > &q)
 
Quaternion< Real > inverse ()
 
void mul (const Quaternion< Real > &q)
 
void mul (const Real &s)
 
void div (Quaternion< Real > &q)
 
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
 
Real get_rotation_angle () const
 
Quaternion< Real > fromAxisAngle (const Vector3< Real > &axis, const Real &angle)
 
void toAxisAngle (Vector3< Real > &axis, Real &angle) const
 
Quaternion< Real > fromShortestArc (const Vector3d &from, const Vector3d &to)
 
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 ()
 
- Public Member Functions inherited from OpenMD::Vector< Real, 4 >
 Vector ()
 
 Vector (const Vector< Real, Dim > &v)
 
 Vector (const Real &s)
 
 Vector (Real *v)
 
Vector< Real, Dim > & operator= (const Vector< Real, Dim > &v)
 
Real & operator[] (unsigned int i)
 
const Real & operator[] (unsigned int i) const
 
Real & operator() (unsigned int i)
 
const Real & operator() (unsigned int i) const
 
void getArray (Real *array)
 
Real * getArrayPointer ()
 
bool operator== (const Vector< Real, Dim > &v)
 
bool operator!= (const Vector< Real, Dim > &v)
 
void zero ()
 
void negate ()
 
void negate (const Vector< Real, Dim > &v1)
 
void add (const Vector< Real, Dim > &v1)
 
void add (const Vector< Real, Dim > &v1, const Vector< Real, Dim > &v2)
 
void sub (const Vector< Real, Dim > &v1)
 
void sub (const Vector< Real, Dim > &v1, const Vector &v2)
 
void mul (Real s)
 
void mul (const Vector< Real, Dim > &v1, Real s)
 
void Vmul (const Vector< Real, Dim > &v1, const Vector< Real, Dim > &v2)
 
Vector< Real, Dim > & abs ()
 
Real max ()
 
void div (Real s)
 
void div (const Vector< Real, Dim > &v1, Real s)
 
void Vdiv (const Vector< Real, Dim > &v1, const Vector< Real, Dim > &v2)
 
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 ()
 
Real componentProduct ()
 
Real length ()
 
Real lengthSquare ()
 
void normalize ()
 
bool isNormalized ()
 
unsigned int size ()
 

Additional Inherited Members

- Public Types inherited from OpenMD::Vector< Real, 4 >
typedef Real ElemType
 
typedef Real * 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 72 of file Quaternion.hpp.

Constructor & Destructor Documentation

◆ Quaternion() [1/3]

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

Definition at line 75 of file Quaternion.hpp.

◆ Quaternion() [2/3]

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

◆ 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 86 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

◆ ComputeTwist()

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

◆ 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 252 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 ( Quaternion< Real > &  q)
inline

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

Definition at line 218 of file Quaternion.hpp.

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

Referenced by OpenMD::Quaternion< Real >::operator/=().

◆ div() [2/2]

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

Definition at line 222 of file Quaternion.hpp.

References OpenMD::Vector< Real, 4 >::data_.

◆ fromAxisAngle()

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

◆ 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 309 of file Quaternion.hpp.

References OpenMD::cross(), OpenMD::Vector< Real, 4 >::data_, 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()

◆ 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 185 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::Quaternion< Real >::getTwistSwingAxisAngle(), OpenMD::operator/(), OpenMD::Quaternion< Real >::operator/=(), and OpenMD::Quaternion< Real >::RemoveTwist().

◆ 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 201 of file Quaternion.hpp.

References OpenMD::Vector< Real, 4 >::data_.

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

◆ mul() [2/2]

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

Definition at line 210 of file Quaternion.hpp.

References OpenMD::Vector< Real, 4 >::data_.

◆ operator*=() [1/2]

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

Definition at line 229 of file Quaternion.hpp.

References OpenMD::Quaternion< Real >::mul().

◆ operator*=() [2/2]

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

Definition at line 234 of file Quaternion.hpp.

References OpenMD::Quaternion< Real >::mul().

◆ operator/=() [1/2]

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

Definition at line 239 of file Quaternion.hpp.

References OpenMD::Quaternion< Real >::inverse().

◆ operator/=() [2/2]

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

Definition at line 244 of file Quaternion.hpp.

References OpenMD::Quaternion< Real >::div().

◆ operator=()

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

copy assignment

Definition at line 91 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 168 of file Quaternion.hpp.

References OpenMD::Vector< Real, 4 >::data_, and OpenMD::equal().

◆ RemoveTwist()

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

◆ rotate()

◆ 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 287 of file Quaternion.hpp.

References tiny, OpenMD::Quaternion< Real >::w(), OpenMD::Vector3< Real >::x(), OpenMD::Quaternion< Real >::x(), OpenMD::Vector3< Real >::y(), OpenMD::Quaternion< Real >::y(), OpenMD::Vector3< Real >::z(), and OpenMD::Quaternion< 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

◆ toTwistSwing()

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

◆ w() [1/2]

◆ w() [2/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 112 of file Quaternion.hpp.

References OpenMD::Vector< Real, 4 >::data_.

◆ x() [1/2]

◆ x() [2/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 128 of file Quaternion.hpp.

References OpenMD::Vector< Real, 4 >::data_.

◆ y() [1/2]

◆ y() [2/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 144 of file Quaternion.hpp.

References OpenMD::Vector< Real, 4 >::data_.

◆ z() [1/2]

◆ z() [2/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 159 of file Quaternion.hpp.

References OpenMD::Vector< Real, 4 >::data_.


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