OpenMD 3.2
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>.
Quaternion & operator= (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< Real, Dim > & operator= (const Vector< Real, Dim > &v)
 copy assignment operator
Real & operator[] (unsigned int i)
 Returns reference of ith element.
Real & operator() (unsigned int i)
 Returns reference of ith element.
void getArray (Real *array) const
 Copy the internal data to an array.
const Real * getArrayPointer () const
 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 add (const Vector< Real, Dim > &v1)
 Sets the value of this vector to the sum of itself and v1 (*this += v1).
void sub (const Vector< Real, Dim > &v1)
 Sets the value of this vector to the difference of itself and v1 (*this -= v1).
void mul (Real s)
 Sets the value of this vector to the scalar multiplication of itself (*this *= s).
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 () const
void div (Real s)
 Sets the value of this vector to the scalar division of itself (*this /= 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 () const
 Returns the sum of all elements of this vector.
Real componentProduct () const
 Returns the product of all elements of this vector.
Real length () const
 Returns the length of this vector.
Real lengthSquare () const
 Returns the squared length of this vector.
void normalize ()
 Normalizes this vector in place.
bool isNormalized () const
 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 79 of file Quaternion.hpp.

Constructor & Destructor Documentation

◆ Quaternion() [1/3]

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

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

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

◆ ComputeTwist()

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

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

◆ div() [1/2]

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

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

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

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

◆ get_rotation_angle()

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

return rotation angle from -PI to PI

Definition at line 246 of file Quaternion.hpp.

◆ getTwistSwingAxisAngle()

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

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

Referenced by OpenMD::Quaternion< RealType >::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 185 of file Quaternion.hpp.

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

◆ mul() [2/2]

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

Definition at line 198 of file Quaternion.hpp.

◆ operator*=() [1/2]

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

Definition at line 216 of file Quaternion.hpp.

◆ operator*=() [2/2]

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

Definition at line 221 of file Quaternion.hpp.

◆ operator/=() [1/2]

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

Definition at line 231 of file Quaternion.hpp.

◆ operator/=() [2/2]

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

Definition at line 226 of file Quaternion.hpp.

◆ operator=()

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

copy assignment

Definition at line 95 of file Quaternion.hpp.

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

◆ RemoveTwist()

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

Definition at line 319 of file Quaternion.hpp.

◆ rotate()

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

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

◆ toRotationMatrix3()

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

Returns the corresponding rotation matrix (3x3).

Returns
a 3x3 rotation matrix

Definition at line 525 of file Quaternion.hpp.

Referenced by OpenMD::SquareMatrix3< RealType >::setupRotMat().

◆ toSwingTwist()

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

Definition at line 485 of file Quaternion.hpp.

◆ toTwistSwing()

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

Definition at line 421 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 113 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 125 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 137 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 148 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: