Mantid
Loading...
Searching...
No Matches
Public Member Functions | List of all members
Mantid::Kernel::Quat Class Reference

Class for quaternions. More...

#include <Geometry/Quat.h>

Public Member Functions

void conjugate ()
 Take the complex conjugate. More...
 
void getAngleAxis (double &_deg, double &_ax0, double &_ax1, double &ax2) const
 Extracts the angle of roatation and axis. More...
 
std::vector< double > getEulerAngles (const std::string &convention) const
 Calculate the Euler angles that are equivalent to this Quaternion. More...
 
std::vector< double > getRotation (bool check_normalisation=false, bool throw_on_errors=false) const
 returns the rotation matrix defined by this quaternion as an 9-point More...
 
void GLMatrix (double *mat) const
 Convert quaternion rotation to an OpenGL matrix [4x4] matrix stored as an linear array of 16 double The function glRotated must be called. More...
 
void init ()
 Re-initialize to identity. More...
 
void inverse ()
 Inverse a quaternion (in the sense of rotation inversion) More...
 
bool isNull (const double tolerance=0.001) const
 Is the quaternion representing a null rotation. More...
 
double len () const
 Norm of a quaternion. More...
 
double len2 () const
 Norm squared. More...
 
void normalize ()
 Normalize. More...
 
bool operator!= (const Quat &) const
 Quaternion non-equal operator. More...
 
void operator() (const double angle, const V3D &)
 Sets the quat values from an angle and a vector. More...
 
void operator() (const double ww, const double aa, const double bb, const double cc)
 Sets the quat values from four doubles. More...
 
void operator() (const Quat &)
 Sets the quat values from another Quat. More...
 
void operator() (const V3D &rX, const V3D &rY, const V3D &rZ)
 Set a Quaternion that performs a reference frame rotation. More...
 
Quat operator* (const Quat &) const
 Quaternion multiplication operator. More...
 
Quatoperator*= (const Quat &)
 Quaternion self-multiplication operator. More...
 
Quat operator+ (const Quat &) const
 Overload operators. More...
 
Quatoperator+= (const Quat &)
 Quaternion self-addition operator. More...
 
Quat operator- (const Quat &) const
 Quaternion subtraction operator. More...
 
Quatoperator-= (const Quat &)
 Quaternion self-substraction operator. More...
 
bool operator== (const Quat &) const
 Quaternion equal operator. More...
 
double & operator[] (int)
 Bracket operator overload returns the internal representation values based on an index. More...
 
double operator[] (int) const
 Bracket operator overload returns the internal representation values based on an index. More...
 
 Quat ()
 Null Constructor Initialize the quaternion with the identity q=1.0+0i+0j+0k;. More...
 
 Quat (const double _deg, const V3D &_axis)
 Set quaternion form an angle in degrees and an axis. More...
 
 Quat (const double _w, const double _a, const double _b, const double _c)
 Constructor with values. More...
 
 Quat (const Matrix< double > &RotMat)
 
 Quat (const V3D &rX, const V3D &rY, const V3D &rZ)
 Construct a Quaternion that performs a reference frame rotation. More...
 
 Quat (const V3D &src, const V3D &des)
 Construct a Quat between two vectors; The angle between them is defined differently from usual if vectors are not unit or the same length vectors, so quat would be not consistent. More...
 
void rotate (V3D &) const
 Rotate a vector. More...
 
void rotateBB (double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) const
 Taking two points defining a cuboid bounding box (xmin,ymin,zmin) and. More...
 
void set (const double ww, const double aa, const double bb, const double cc)
 Sets the quat values from four doubles. More...
 
void setAngleAxis (const double _deg, const V3D &_axis)
 Constructor from an angle and axis. More...
 
void setQuat (const Matrix< double > &rMat)
 Convert usual 3D rotation matrix into quat; Will throw if matirix is not. More...
 
void setQuat (double mat[16])
 Convert GL Matrix into Quat. More...
 
void setRotation (const double deg)
 Set the rotation (both don't change rotation axis) More...
 

Element access.

double w
 Internal value. More...
 
double a
 Internal value. More...
 
double b
 Internal value. More...
 
double c
 Internal value. More...
 
double real () const
 Access the real part. More...
 
double imagI () const
 Access the coefficient of i. More...
 
double imagJ () const
 Access the coefficient of j. More...
 
double imagK () const
 Access the coefficient of k. More...
 
void printSelf (std::ostream &) const
 Prints a string representation of itself. More...
 
void readPrinted (std::istream &)
 Read data from a stream in the format returned by printSelf ("[w,a,b,c]"). More...
 
std::string toString () const
 
void fromString (const std::string &str)
 Sets the Quat using a string. More...
 

Detailed Description

Class for quaternions.

Version
1.0
Author
Laurent C Chapon, ISIS RAL
Date
10/10/2007

Templated class for quaternions. Quaternions are the 3D generalization of complex numbers Quaternions are used for rotations in 3D spaces and often implemented for computer graphics applications. Quaternion can be written q=W+ai+bj+ck where w is the scalar part, and a, b, c the 3 imaginary parts. Quaternion multiplication is non-commutative.
i*j=-j*i=k
j*k=-k*j=i
k*i=-i*k=j
Rotation of an angle theta around a normalized axis (u,v,w) can be simply written W=cos(theta/2), a=u*sin(theta/2), b=v*sin(theta/2), c=w*sin(theta/2) This class support all arithmetic operations for quaternions

Definition at line 39 of file Quat.h.

Constructor & Destructor Documentation

◆ Quat() [1/6]

Mantid::Kernel::Quat::Quat ( )

Null Constructor Initialize the quaternion with the identity q=1.0+0i+0j+0k;.

Definition at line 24 of file Quat.cpp.

Referenced by getEulerAngles(), operator*(), operator+(), and operator-().

◆ Quat() [2/6]

Mantid::Kernel::Quat::Quat ( const double  _w,
const double  _a,
const double  _b,
const double  _c 
)

Constructor with values.

Definition at line 65 of file Quat.cpp.

◆ Quat() [3/6]

Mantid::Kernel::Quat::Quat ( const V3D src,
const V3D des 
)

Construct a Quat between two vectors; The angle between them is defined differently from usual if vectors are not unit or the same length vectors, so quat would be not consistent.

v=(src+des)/(src+des) w=v.des (a,b,c)=(v x des)

Parameters
src:: the source position
des:: the destination position

Definition at line 37 of file Quat.cpp.

References a, b, c, Mantid::Kernel::V3D::cross_prod(), fabs, Mantid::Kernel::normalize(), Mantid::Kernel::V3D::nullVector(), Mantid::Kernel::V3D::scalar_prod(), and w.

◆ Quat() [4/6]

Mantid::Kernel::Quat::Quat ( const V3D rX,
const V3D rY,
const V3D rZ 
)

Construct a Quaternion that performs a reference frame rotation.

Specify the X,Y,Z vectors of the rotated reference frame, assuming that the initial X,Y,Z vectors are aligned as expected: X=(1,0,0), Y=(0,1,0), Z=(0,0,1). The resuting quaternion rotates XYZ axes onto the provided rX, rY, rZ.

Parameters
rX:: rotated X reference axis; unit vector.
rY:: rotated Y reference axis; unit vector.
rZ:: rotated Z reference axis; unit vector.

Definition at line 88 of file Quat.cpp.

References operator()().

◆ Quat() [5/6]

Mantid::Kernel::Quat::Quat ( const double  _deg,
const V3D _axis 
)

Set quaternion form an angle in degrees and an axis.

Constructor from an angle and axis.

This construct a quaternion to represent a rotation of an angle _deg around the _axis. The _axis does not need to be a unit vector

Parameters
_deg:: angle of rotation
_axis:: axis to rotate about

Definition at line 75 of file Quat.cpp.

References setAngleAxis().

◆ Quat() [6/6]

Mantid::Kernel::Quat::Quat ( const Matrix< double > &  RotMat)

Definition at line 62 of file Quat.cpp.

References setQuat().

Member Function Documentation

◆ conjugate()

void Mantid::Kernel::Quat::conjugate ( )

Take the complex conjugate.

Quaternion complex conjugate.

Reverse the sign of the 3 imaginary components of the quaternion

Definition at line 357 of file Quat.cpp.

References a, b, and c.

Referenced by Mantid::API::applyRectangularDetectorScaleToComponentInfo(), and inverse().

◆ fromString()

void Mantid::Kernel::Quat::fromString ( const std::string &  str)

Sets the Quat using a string.

Parameters
str:: the Quat as a string "[w,a,b,c]"

Definition at line 665 of file Quat.cpp.

References readPrinted().

Referenced by Mantid::Geometry::ComponentParser::endElement().

◆ getAngleAxis()

void Mantid::Kernel::Quat::getAngleAxis ( double &  _deg,
double &  _ax0,
double &  _ax1,
double &  _ax2 
) const

Extracts the angle of roatation and axis.

Parameters
_deg:: the angle of rotation
_ax0:: The first component of the axis
_ax1:: The second component of the axis
_ax2:: The third component of the axis

Definition at line 135 of file Quat.cpp.

References a, b, c, isNull(), and w.

Referenced by Mantid::Crystal::GoniometerAnglesFromPhiRotation::exec(), Mantid::Crystal::SCDCalibratePanels2::generateCalibrationTable(), and setRotation().

◆ getEulerAngles()

std::vector< double > Mantid::Kernel::Quat::getEulerAngles ( const std::string &  convention = "XYZ") const

Calculate the Euler angles that are equivalent to this Quaternion.

Euler angles are calculated intrinsically, i.e. the first rotation modifies the axis used for the second rotation, and the second rotation modifies the axis used for the third rotation.

You can specify which axis the rotations should be applied around and the order in which they are to be applied with the convention parameter. For instance, for a rotation of Y and then the new Z axis, and then the new Y axis: pass "YZY" as the convention. Or for a rotation such as X, and then the new Y axis, and then the new Z axis: pass "XYZ" as the convention.

Parameters
convention:: The axes to apply the rotations to and the order in which to do so. Defaults to "XYZ".
Returns
A vector of the Euler angles in degrees. The order of the angles is the same as in the convention parameter.

Definition at line 729 of file Quat.cpp.

References getRotation(), Quat(), and Mantid::DataHandling::rad2deg.

Referenced by export_Quat(), Mantid::Geometry::Goniometer::getEulerAngles(), Mantid::Crystal::SCDCalibratePanels::saveXmlFile(), and Mantid::Crystal::SCDCalibratePanels2::saveXmlFile().

◆ getRotation()

std::vector< double > Mantid::Kernel::Quat::getRotation ( bool  check_normalisation = false,
bool  throw_on_errors = false 
) const

◆ GLMatrix()

void Mantid::Kernel::Quat::GLMatrix ( double *  mat) const

Convert quaternion rotation to an OpenGL matrix [4x4] matrix stored as an linear array of 16 double The function glRotated must be called.

Parameters
mat:: The output matrix

Definition at line 413 of file Quat.cpp.

References a, b, c, and w.

Referenced by rotateBB().

◆ imagI()

double Mantid::Kernel::Quat::imagI ( ) const
inline

Access the coefficient of i.

Definition at line 119 of file Quat.h.

Referenced by export_Quat(), and Mantid::Kernel::toQuaterniond().

◆ imagJ()

double Mantid::Kernel::Quat::imagJ ( ) const
inline

Access the coefficient of j.

Definition at line 121 of file Quat.h.

Referenced by export_Quat(), and Mantid::Kernel::toQuaterniond().

◆ imagK()

double Mantid::Kernel::Quat::imagK ( ) const
inline

Access the coefficient of k.

Definition at line 123 of file Quat.h.

Referenced by export_Quat(), and Mantid::Kernel::toQuaterniond().

◆ init()

void Mantid::Kernel::Quat::init ( )

Re-initialize to identity.

Re-initialise a quaternion to identity.

Definition at line 236 of file Quat.cpp.

References a, b, c, and w.

◆ inverse()

void Mantid::Kernel::Quat::inverse ( )

Inverse a quaternion (in the sense of rotation inversion)

Inverse a quaternion.

Definition at line 376 of file Quat.cpp.

References a, b, c, conjugate(), len2(), and w.

Referenced by Mantid::Crystal::IntegratePeakTimeSlices::FindPlane(), Mantid::Geometry::InstrumentDefinitionParser::makeXYplaneFaceComponent(), rotate(), and Mantid::Geometry::ObjComponent::takeOutRotation().

◆ isNull()

bool Mantid::Kernel::Quat::isNull ( const double  tolerance = 0.001) const

Is the quaternion representing a null rotation.

Definition at line 124 of file Quat.cpp.

References fabs, tolerance, and w.

Referenced by getAngleAxis().

◆ len()

double Mantid::Kernel::Quat::len ( ) const

Norm of a quaternion.

Quaternion length.

Returns
the length

Definition at line 366 of file Quat.cpp.

References len2().

Referenced by export_Quat(), and normalize().

◆ len2()

double Mantid::Kernel::Quat::len2 ( ) const

Norm squared.

Quaternion norm (length squared)

Returns
the length squared

Definition at line 371 of file Quat.cpp.

References a, b, c, and w.

Referenced by export_Quat(), inverse(), len(), and normalize().

◆ normalize()

void Mantid::Kernel::Quat::normalize ( )

Normalize.

Quaternion normalization.

Divide all elements by the quaternion norm

Definition at line 340 of file Quat.cpp.

References a, b, c, len(), len2(), and w.

Referenced by Mantid::Crystal::GoniometerAnglesFromPhiRotation::exec().

◆ operator!=()

bool Mantid::Kernel::Quat::operator!= ( const Quat _q) const

Quaternion non-equal operator.

Parameters
_q:: the quaternion to compare

Compare two quaternions at 1e-6tolerance. Use boost close_at_tolerance method

Returns
true if not equal

Definition at line 334 of file Quat.cpp.

◆ operator()() [1/4]

void Mantid::Kernel::Quat::operator() ( const double  angle,
const V3D axis 
)

Sets the quat values from an angle and a vector.

Parameters
angle:: the numbers of degrees
axis:: the axis of rotation

Definition at line 176 of file Quat.cpp.

References setAngleAxis().

◆ operator()() [2/4]

void Mantid::Kernel::Quat::operator() ( const double  ww,
const double  aa,
const double  bb,
const double  cc 
)

Sets the quat values from four doubles.

Parameters
ww:: the value for w
aa:: the value for a
bb:: the value for b
cc:: the value for c

Definition at line 170 of file Quat.cpp.

References set().

◆ operator()() [3/4]

void Mantid::Kernel::Quat::operator() ( const Quat q)

Sets the quat values from another Quat.

Parameters
q:: the quat to copy

Definition at line 181 of file Quat.cpp.

References a, b, c, and w.

Referenced by operator()(), and Quat().

◆ operator()() [4/4]

void Mantid::Kernel::Quat::operator() ( const V3D rX,
const V3D rY,
const V3D rZ 
)

Set a Quaternion that performs a reference frame rotation.

Specify the X,Y,Z vectors of the rotated reference frame, assuming that the initial X,Y,Z vectors are aligned as expected: X=(1,0,0), Y=(0,1,0), Z=(0,0,1). The resuting quaternion rotates XYZ axes onto the provided rX, rY, rZ.

Parameters
rX:: rotated X reference axis; unit vector.
rY:: rotated Y reference axis; unit vector.
rZ:: rotated Z reference axis; unit vector.

Definition at line 199 of file Quat.cpp.

References Mantid::Kernel::V3D::angle(), Mantid::Kernel::V3D::cross_prod(), Mantid::Kernel::V3D::nullVector(), operator()(), rotate(), and setAngleAxis().

◆ operator*()

Quat Mantid::Kernel::Quat::operator* ( const Quat _q) const

Quaternion multiplication operator.

Parameters
_q:: the quaternion to multiply
Returns
this_q

Quaternion multiplication is non commutative in the same way multiplication of rotation matrices isn't.

Definition at line 285 of file Quat.cpp.

References a, b, c, Quat(), and w.

◆ operator*=()

Quat & Mantid::Kernel::Quat::operator*= ( const Quat _q)

Quaternion self-multiplication operator.

Parameters
_q:: the quaternion to multiply
Returns
this=_q

Definition at line 298 of file Quat.cpp.

References a, b, c, and w.

◆ operator+()

Quat Mantid::Kernel::Quat::operator+ ( const Quat _q) const

Overload operators.

Quaternion addition operator.

Parameters
_q:: the quaternion to add
Returns
*this+_q

Definition at line 245 of file Quat.cpp.

References a, b, c, Quat(), and w.

◆ operator+=()

Quat & Mantid::Kernel::Quat::operator+= ( const Quat _q)

Quaternion self-addition operator.

Parameters
_q:: the quaternion to add
Returns
*this+=_q

Definition at line 251 of file Quat.cpp.

References a, b, c, and w.

◆ operator-()

Quat Mantid::Kernel::Quat::operator- ( const Quat _q) const

Quaternion subtraction operator.

Parameters
_q:: the quaternion to add
Returns
*this-_q

Definition at line 263 of file Quat.cpp.

References a, b, c, Quat(), and w.

◆ operator-=()

Quat & Mantid::Kernel::Quat::operator-= ( const Quat _q)

Quaternion self-substraction operator.

Parameters
_q:: the quaternion to add
Returns
*this-=_q

Definition at line 269 of file Quat.cpp.

References a, b, c, and w.

◆ operator==()

bool Mantid::Kernel::Quat::operator== ( const Quat q) const

Quaternion equal operator.

Parameters
q:: the quaternion to compare

Compare two quaternions at 1e-6tolerance. Use boost close_at_tolerance method

Returns
true if equal

Definition at line 318 of file Quat.cpp.

References a, b, c, fabs, Mantid::Kernel::Tolerance, and w.

◆ operator[]() [1/2]

double & Mantid::Kernel::Quat::operator[] ( int  Index)

Bracket operator overload returns the internal representation values based on an index.

Parameters
Index:: the index of the value required 0=w, 1=a, 2=b, 3=c
Returns
a double of the value requested

Definition at line 591 of file Quat.cpp.

References a, b, c, and w.

◆ operator[]() [2/2]

double Mantid::Kernel::Quat::operator[] ( int  Index) const

Bracket operator overload returns the internal representation values based on an index.

Parameters
Index:: the index of the value required 0=w, 1=a, 2=b, 3=c
Returns
a double of the value requested

Definition at line 571 of file Quat.cpp.

References a, b, c, and w.

◆ printSelf()

void Mantid::Kernel::Quat::printSelf ( std::ostream &  os) const

Prints a string representation of itself.

Parameters
os:: the stream to output to

Definition at line 609 of file Quat.cpp.

References a, b, c, and w.

Referenced by Mantid::Kernel::operator<<(), and toString().

◆ readPrinted()

void Mantid::Kernel::Quat::readPrinted ( std::istream &  IX)

Read data from a stream in the format returned by printSelf ("[w,a,b,c]").

Parameters
IX:: Input Stream
Exceptions
std::runtime_errorif the input is of wrong format

Definition at line 615 of file Quat.cpp.

References a, b, c, and w.

Referenced by fromString(), and Mantid::Kernel::operator>>().

◆ real()

double Mantid::Kernel::Quat::real ( ) const
inline

Access the real part.

Definition at line 117 of file Quat.h.

Referenced by export_Quat(), and Mantid::Kernel::toQuaterniond().

◆ rotate()

void Mantid::Kernel::Quat::rotate ( V3D v) const

◆ rotateBB()

void Mantid::Kernel::Quat::rotateBB ( double &  xmin,
double &  ymin,
double &  zmin,
double &  xmax,
double &  ymax,
double &  zmax 
) const

Taking two points defining a cuboid bounding box (xmin,ymin,zmin) and.

Definition at line 670 of file Quat.cpp.

References GLMatrix(), and index.

◆ set()

void Mantid::Kernel::Quat::set ( const double  ww,
const double  aa,
const double  bb,
const double  cc 
)

Sets the quat values from four doubles.

Parameters
ww:: the value for w
aa:: the value for a
bb:: the value for b
cc:: the value for c

Definition at line 99 of file Quat.cpp.

References a, b, c, and w.

Referenced by operator()().

◆ setAngleAxis()

void Mantid::Kernel::Quat::setAngleAxis ( const double  _deg,
const V3D _axis 
)

Constructor from an angle and axis.

Parameters
_deg:: angle of rotation
_axis:: axis to rotate about

This construct a quaternion to represent a rotation of an angle _deg around the _axis. The _axis does not need to be a unit vector

Definition at line 114 of file Quat.cpp.

References a, b, c, Mantid::Geometry::deg2rad, Mantid::Kernel::normalize(), and w.

Referenced by Mantid::DataHandling::LoadIsawDetCal::doRotation(), Mantid::Geometry::IndexingUtils::MakeCircleDirections(), operator()(), Quat(), and setRotation().

◆ setQuat() [1/2]

void Mantid::Kernel::Quat::setQuat ( const Matrix< double > &  rMat)

Convert usual 3D rotation matrix into quat; Will throw if matirix is not.

Using the convention at http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation.

Definition at line 540 of file Quat.cpp.

References a, b, c, and w.

◆ setQuat() [2/2]

void Mantid::Kernel::Quat::setQuat ( double  mat[16])

Convert GL Matrix into Quat.

Converts the GL Matrix into Quat.

Definition at line 506 of file Quat.cpp.

References a, b, c, and w.

Referenced by Quat().

◆ setRotation()

void Mantid::Kernel::Quat::setRotation ( const double  deg)

Set the rotation (both don't change rotation axis)

Set the rotation (but don't change rotation axis).

Parameters
deg:: angle of rotation

Definition at line 158 of file Quat.cpp.

References getAngleAxis(), and setAngleAxis().

Referenced by Mantid::DataHandling::RotateInstrumentComponent::exec(), and Mantid::Kernel::V3D::makeVectorsOrthogonal().

◆ toString()

std::string Mantid::Kernel::Quat::toString ( ) const
Returns
the quat as a string "[w,a,b,c]"

Definition at line 657 of file Quat.cpp.

References printSelf().

Referenced by export_Quat().

Member Data Documentation

◆ a

double Mantid::Kernel::Quat::a
private

◆ b

double Mantid::Kernel::Quat::b
private

◆ c

double Mantid::Kernel::Quat::c
private

◆ w

double Mantid::Kernel::Quat::w
private

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