Mantid
|
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... | |
Quat & | operator*= (const Quat &) |
Quaternion self-multiplication operator. More... | |
Quat | operator+ (const Quat &) const |
Overload operators. More... | |
Quat & | operator+= (const Quat &) |
Quaternion self-addition operator. More... | |
Quat | operator- (const Quat &) const |
Quaternion subtraction operator. More... | |
Quat & | operator-= (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... | |
Class for quaternions.
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
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-().
Mantid::Kernel::Quat::Quat | ( | const double | _w, |
const double | _a, | ||
const double | _b, | ||
const double | _c | ||
) |
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)
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.
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.
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()().
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
_deg | :: angle of rotation |
_axis | :: axis to rotate about |
Definition at line 75 of file Quat.cpp.
References setAngleAxis().
Mantid::Kernel::Quat::Quat | ( | const Matrix< double > & | RotMat | ) |
void Mantid::Kernel::Quat::conjugate | ( | ) |
void Mantid::Kernel::Quat::fromString | ( | const std::string & | str | ) |
Sets the Quat using a string.
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().
void Mantid::Kernel::Quat::getAngleAxis | ( | double & | _deg, |
double & | _ax0, | ||
double & | _ax1, | ||
double & | _ax2 | ||
) | const |
Extracts the angle of roatation and axis.
_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().
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.
convention | :: The axes to apply the rotations to and the order in which to do so. Defaults to "XYZ". |
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().
std::vector< double > Mantid::Kernel::Quat::getRotation | ( | bool | check_normalisation = false , |
bool | throw_on_errors = false |
||
) | const |
returns the rotation matrix defined by this quaternion as an 9-point
using convention at http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation
(m33 is not used at the moment), if check_normalisation selected, verify
Definition at line 453 of file Quat.cpp.
References a, b, c, Mantid::Kernel::Logger::error(), fabs, Mantid::Kernel::DateAndTimeHelpers::g_log, Mantid::Kernel::Logger::information(), and w.
Referenced by Mantid::Crystal::CalibrationHelpers::adjustBankPositionsAndSizes(), Mantid::Algorithms::DetectorEfficiencyCor::correctForEfficiency(), ComponentCreationHelper::createCuboid(), Mantid::Crystal::CalculateUMatrix::exec(), Mantid::Crystal::GoniometerAnglesFromPhiRotation::exec(), Mantid::DataHandling::RotateInstrumentComponent::exec(), Mantid::Crystal::IntegratePeakTimeSlices::FindPlane(), getEulerAngles(), Mantid::Geometry::Component::getPos(), Mantid::Geometry::Component::getRotation(), and Mantid::Geometry::Goniometer::recalculateR().
void Mantid::Kernel::Quat::GLMatrix | ( | double * | mat | ) | const |
|
inline |
Access the coefficient of i.
Definition at line 119 of file Quat.h.
Referenced by export_Quat(), and Mantid::Kernel::toQuaterniond().
|
inline |
Access the coefficient of j.
Definition at line 121 of file Quat.h.
Referenced by export_Quat(), and Mantid::Kernel::toQuaterniond().
|
inline |
Access the coefficient of k.
Definition at line 123 of file Quat.h.
Referenced by export_Quat(), and Mantid::Kernel::toQuaterniond().
void Mantid::Kernel::Quat::init | ( | ) |
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().
bool Mantid::Kernel::Quat::isNull | ( | const double | tolerance = 0.001 | ) | const |
double Mantid::Kernel::Quat::len | ( | ) | const |
Norm of a quaternion.
Quaternion length.
Definition at line 366 of file Quat.cpp.
References len2().
Referenced by export_Quat(), and normalize().
double Mantid::Kernel::Quat::len2 | ( | ) | const |
Norm squared.
Quaternion norm (length squared)
Definition at line 371 of file Quat.cpp.
Referenced by export_Quat(), inverse(), len(), and normalize().
void Mantid::Kernel::Quat::normalize | ( | ) |
bool Mantid::Kernel::Quat::operator!= | ( | const Quat & | _q | ) | const |
void Mantid::Kernel::Quat::operator() | ( | const double | angle, |
const V3D & | axis | ||
) |
Sets the quat values from an angle and a vector.
angle | :: the numbers of degrees |
axis | :: the axis of rotation |
Definition at line 176 of file Quat.cpp.
References setAngleAxis().
void Mantid::Kernel::Quat::operator() | ( | const double | ww, |
const double | aa, | ||
const double | bb, | ||
const double | cc | ||
) |
void Mantid::Kernel::Quat::operator() | ( | const Quat & | q | ) |
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.
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().
bool Mantid::Kernel::Quat::operator== | ( | const Quat & | q | ) | const |
double & Mantid::Kernel::Quat::operator[] | ( | int | Index | ) |
double Mantid::Kernel::Quat::operator[] | ( | int | Index | ) | const |
void Mantid::Kernel::Quat::printSelf | ( | std::ostream & | os | ) | const |
Prints a string representation of itself.
os | :: the stream to output to |
Definition at line 609 of file Quat.cpp.
Referenced by Mantid::Kernel::operator<<(), and toString().
void Mantid::Kernel::Quat::readPrinted | ( | std::istream & | IX | ) |
Read data from a stream in the format returned by printSelf ("[w,a,b,c]").
IX | :: Input Stream |
std::runtime_error | if the input is of wrong format |
Definition at line 615 of file Quat.cpp.
Referenced by fromString(), and Mantid::Kernel::operator>>().
|
inline |
Access the real part.
Definition at line 117 of file Quat.h.
Referenced by export_Quat(), and Mantid::Kernel::toQuaterniond().
void Mantid::Kernel::Quat::rotate | ( | V3D & | v | ) | const |
Rotate a vector.
v | :: the vector to be rotated |
The quaternion needs to be normalized beforehand to represent a rotation. If q is thequaternion, the rotation is represented by q.v.q-1 where q-1 is the inverse of v.
Definition at line 397 of file Quat.cpp.
References inverse().
Referenced by Mantid::DataObjects::ScanningWorkspaceBuilder::buildRelativeRotationsForScans(), Mantid::Algorithms::He3TubeEfficiency::calculateExponential(), Mantid::Algorithms::DetectorEfficiencyCor::correctForEfficiency(), Mantid::DataHandling::LoadIsawDetCal::doRotation(), Mantid::DataHandling::RotateSource::exec(), export_Quat(), Mantid::Crystal::IntegratePeakTimeSlices::FindPlane(), Mantid::Geometry::ObjComponent::getPointInObject(), Mantid::Geometry::Component::getPos(), Mantid::Geometry::ObjComponent::interceptSurface(), Mantid::Geometry::IndexingUtils::MakeCircleDirections(), Mantid::Kernel::V3D::makeVectorsOrthogonal(), Mantid::Geometry::InstrumentDefinitionParser::makeXYplaneFaceComponent(), operator()(), Mantid::Geometry::ShapeFactory::parseCuboid(), Mantid::Geometry::ShapeFactory::parseTaperedGuide(), Mantid::Geometry::CSGObject::rayTraceSolidAngle(), and Mantid::Geometry::ObjComponent::takeOutRotation().
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.
void Mantid::Kernel::Quat::set | ( | const double | ww, |
const double | aa, | ||
const double | bb, | ||
const double | cc | ||
) |
void Mantid::Kernel::Quat::setAngleAxis | ( | const double | _deg, |
const V3D & | _axis | ||
) |
Constructor from an angle and axis.
_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().
void Mantid::Kernel::Quat::setQuat | ( | const Matrix< double > & | rMat | ) |
void Mantid::Kernel::Quat::setQuat | ( | double | mat[16] | ) |
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).
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().
std::string Mantid::Kernel::Quat::toString | ( | ) | const |
Definition at line 657 of file Quat.cpp.
References printSelf().
Referenced by export_Quat().
|
private |
Internal value.
Definition at line 135 of file Quat.h.
Referenced by conjugate(), getAngleAxis(), getRotation(), GLMatrix(), init(), inverse(), len2(), normalize(), operator()(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-=(), operator==(), operator[](), printSelf(), Quat(), readPrinted(), set(), setAngleAxis(), and setQuat().
|
private |
Internal value.
Definition at line 137 of file Quat.h.
Referenced by conjugate(), getAngleAxis(), getRotation(), GLMatrix(), init(), inverse(), len2(), normalize(), operator()(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-=(), operator==(), operator[](), printSelf(), Quat(), readPrinted(), set(), setAngleAxis(), and setQuat().
|
private |
Internal value.
Definition at line 139 of file Quat.h.
Referenced by conjugate(), getAngleAxis(), getRotation(), GLMatrix(), init(), inverse(), len2(), normalize(), operator()(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-=(), operator==(), operator[](), printSelf(), Quat(), readPrinted(), set(), setAngleAxis(), and setQuat().
|
private |
Internal value.
Definition at line 133 of file Quat.h.
Referenced by getAngleAxis(), getRotation(), GLMatrix(), init(), inverse(), isNull(), len2(), normalize(), operator()(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-=(), operator==(), operator[](), printSelf(), Quat(), readPrinted(), set(), setAngleAxis(), and setQuat().