A implementation of a way of representing rotations that avoid a lot of the problems that the standard rotation about the axis methods have. More...
Public Member Functions | |
Quaternion () | |
Default constructor. | |
Quaternion (double a, double b, double c, double d) | |
Constructor for specifying values. | |
void | set (double a, double b, double c, double d) |
Set individual quaternion values. | |
Quaternion (double sval, const Vector3 &v) | |
This constructor takes an angle in radians and a vector to rotate around. | |
Quaternion (const Matrix4 &mat) | |
Constructor. Given a Matrix that represents a rotation, calculate the quaternion that is equivalent to that rotation. | |
Quaternion (const Vector3 &org_vec, const Vector3 &new_vec) | |
Quaternion | operator+ (const Quaternion &q) const |
Addition of two quaternions. This follows this rule: | |
Quaternion | operator* (const Quaternion &q) const |
Multiplication of two quaternions. This follows this rule: | |
Quaternion | operator* (double f) const |
Multiplication of a quaternion by a double number. This follows this rule: | |
Quaternion | conjugate () const |
Returns the cojungate of this quaternion. This follows this rule: q.conjugate = ( s - v ) | |
double | magnitude () const |
Returns (the square of?) the magnitude of the quaternion. This follows this rule: | |
Quaternion | add_inverse () const |
Returns the additive inverse of the quaternion. This is: q.add_inverse = ( -s, -vx, -vy, -vz ) | |
Quaternion | mult_inverse () const |
Returns the multiplicative inverse of the quaternion. This is: q.mult_inverse = ( 1 / q.magnitude ) * q.conjugate | |
Quaternion | slerp (const Quaternion &end_quat, double t) const |
Spherical linear interpolation. This method interpolates smoothly between two quaternions. The value t should be a number between 0.0 and 1.0. When t = 0.0, *this is returned. When t = 1.0, end_quat is returned. | |
Matrix4 | matrix () const |
Return the transformation matrix that will represent the the Euler angle rotations that this quaternion embodies. Note - this method affects all components of the matrix. | |
Matrix4 | matrix2 () const |
Return the transformation matrix that will represent the the Euler angle rotations that this quaternion embodies. Note - this method only affects the rotation part of the matrix. NOTE: The quaternion must be normalised before using this function. | |
void | normalize () |
Static Public Member Functions | |
static Quaternion | add_identity () |
Returns the additive identity for quaternions (which is all zeros) | |
static Quaternion | mult_identity () |
Returns the multipicative identity for quaternions (which is 1,0,0,0) | |
Public Attributes | |
double | s |
double | vx |
double | vy |
double | vz |
Friends | |
std::ostream & | operator<< (std::ostream &o, const Quaternion &q) |
Writes it in nuke/tcl notation "{s x y z}". |
A implementation of a way of representing rotations that avoid a lot of the problems that the standard rotation about the axis methods have.
Quaternions are a modification of the concept of a vector in space, but specially tailored for spherical space. The cool thing about quaternions is that they are perfectly suited to representing rotations and orientations of objects in three space.
Basically, in a quaternion there are four values: a scalar part and a vector part. q = ( s, v ). Typically, when dealing with rotations, the scalar part represents the rotation about an arbitrary axis. The axis is represented by a unit vector in the vector part.
Since the quaternion is a representation of a rotation, it can be converted into a Euler angle rotation matrix and a rotation matrix can be converted into a quaternion.
Copyright (c) 2009 The Foundry Visionmongers Ltd. All Rights Reserved.
Quaternion::Quaternion | ( | const Matrix4 & | mat | ) |
Constructor. Given a Matrix that represents a rotation, calculate the quaternion that is equivalent to that rotation.
Given a Matrix that represents a rotation, calculate the quaternion that is equivalent to that rotation. A matrix3 could be used instead, last row and column are ignored.
Constructor from two vectors. The quaternion will represent the angle between the two vectors.
References DD::Image::Vector3::cross(), DD::Image::Vector3::dot(), DD::Image::Vector3::length(), DD::Image::Vector3::lengthSquared(), and DD::Image::Vector3::normalize().
Quaternion DD::Image::Quaternion::operator+ | ( | const Quaternion & | q | ) | const [inline] |
Addition of two quaternions. This follows this rule:
q1 + q2 = ( s1 + s2, vx1 + vx2, vy1 + vy2, vz1 + vz2 )
Quaternion DD::Image::Quaternion::operator* | ( | const Quaternion & | q | ) | const [inline] |
Multiplication of two quaternions. This follows this rule:
q1 q2 = ( s1 s2 - vx1 vx2 - vy1 vy2 - vz1 vz2, vy1 vz2 - vy2 vz1 + s1 vx2 + s2 vx1, vz1 vx2 - vz2 vx1 + s1 vy2 + s2 vy1, vx1 vy2 - vx2 vy1 + s1 vz2 + s2 vz1 ))
(I think this is the same as doing the two rotations one after another?)
Quaternion DD::Image::Quaternion::operator* | ( | double | f | ) | const [inline] |
Multiplication of a quaternion by a double number. This follows this rule:
f * q = ( f * s, f * vx, f * vy, f * vz )
double DD::Image::Quaternion::magnitude | ( | ) | const [inline] |
Returns (the square of?) the magnitude of the quaternion. This follows this rule:
q.magnitude = q q.conjugate = s^2 + vx^2 + vy^2 + vz^2
Huh? This does not match the code...
Quaternion Quaternion::slerp | ( | const Quaternion & | end_quat, |
double | t | ||
) | const |
Spherical linear interpolation. This method interpolates smoothly between two quaternions. The value t should be a number between 0.0 and 1.0. When t = 0.0, *this is returned. When t = 1.0, end_quat is returned.
Spherical linear interpolation. This method interpolates smoothly between two quaternions. The value t should be a number between 0.0 and 1.0. When t = 0.0, *this is returned. When t = 1.0, end_quat is returned.
Because of the way quaternions work, you can't just linearly interpolate between two of them. You must interpolate along the surface of a sphere. This method returns a quaternion that is between the current quaternion and the end_quat. The value of t (which should be between 0 and 1) determines the amount of interpolation.
Matrix4 Quaternion::matrix | ( | ) | const |
Return the transformation matrix that will represent the the Euler angle rotations that this quaternion embodies. Note - this method affects all components of the matrix.
Return the transformation matrix that will represent the the Euler angle rotations that this quaternion embodies.
References DD::Image::Matrix4::transpose().