|
World of Rigid Bodies (WoRB)
|
Encapsulates Hamilton real quaternions. More...
#include <Quaternion.h>

Public Member Functions | |
| void | Dump (const char *name) const |
Indexing operators | |
| double | operator[] (unsigned index) const |
| double & | operator[] (unsigned index) |
Methods acting on quaterinion components | |
| Quaternion & | Normalize (double length=1.0) |
| Normalizes the quaternion to a given length. | |
| Quaternion & | Trim (double size) |
| Limits the size of the quaternion to the given maximum. | |
| Quaternion & | Zeroize (double eps=1e-4) |
| Removes the quaternion components that are bellow the limit. | |
Unary operations | |
| Quaternion | operator- () const |
| Flips signs of all the components of the quaternion. | |
| Quaternion | Conjugate () const |
| Returns the conjugate of the quaternion. | |
| double | SquaredNorm () const |
| Gets the squared magnitude of this quaternion. | |
| double | ReSquaredNorm () const |
| Gets the squared magnitude of the scalar part of this quaternion. | |
| double | ImSquaredNorm () const |
| Gets the squared magnitude of the vector part of this quaternion. | |
| double | Norm () const |
| Gets the magnitude of this quaternion. | |
| double | ImNorm () const |
| Gets the magnitude of the vector part of this quaternion. | |
| Quaternion | Unit (double length=1.0) const |
| Returns the normalized version (versor) of a quaternion. | |
Binary operations | |
| Quaternion | operator+ (const Quaternion &q) const |
| Returns the value of the given quaternion added to this. | |
| Quaternion & | operator+= (const Quaternion &q) |
| Adds the given quaternion to this. | |
| Quaternion | operator- (const Quaternion &q) const |
| Returns the value of the given quaternion subtracted from this. | |
| Quaternion | operator-= (const Quaternion &q) |
| Subtracts the given quaternion from this. | |
| Quaternion | operator* (const Quaternion &q) const |
| Multiplies the quaternion by the given quaternion. | |
| Quaternion & | operator*= (const Quaternion &right) |
| Multiplies the quaternion by the given quaternion. | |
| Quaternion | operator* (double value) const |
| Returns a copy of this quaternion scaled the given scalar value. | |
| Quaternion & | operator*= (double value) |
| Multiplies this quaternion by the given scalar value. | |
| Quaternion | ComponentWiseProduct (const Quaternion &q) const |
| Returns a component-wise product of this and another quaternion. | |
| Quaternion | Cross (const Quaternion &q) const |
| Returns a vector product of the vector parts of this and another quaternion. | |
| double | Dot (const Quaternion &q) const |
| Returns a scalar product of the vector parts of this and another quaternion. | |
Comparison operators | |
| bool | operator== (const Quaternion &q) const |
| Checks if the two quaternions have identical components. | |
| bool | operator!= (const Quaternion &q) const |
| Checks if the two vectors have non-identical components. | |
| bool | operator< (const Quaternion &q) const |
| Checks if this quaternion is component-by-component less than the other. | |
| bool | operator> (const Quaternion &q) const |
| Checks if this quaternion is component-by-component less than the other. | |
| bool | operator<= (const Quaternion &q) const |
| Checks if this quaternion is component-by-component less than the other. | |
| bool | operator>= (const Quaternion &q) const |
| Checks if this quaternion is component-by-component less than the other. | |
Data Fields | |
Quaternion components | |
| |
| double | w |
| Holds the real (scalar) part of the quaternion. | |
| double | x |
| Holds i-component of the pure imaginary (vector) part. | |
| double | y |
| Holds j-component of the pure imaginary (vector) part. | |
| double | z |
| Holds k-component of the pure imaginary (vector) part. | |
Constructors and assignment operators | |
| Quaternion () | |
| The default constructor; creates a zero quaternion. | |
| Quaternion (double scalar) | |
| Creates a quaternion having only the scalar (real) part. | |
| Quaternion (double w, double x, double y, double z) | |
| Creates a quaternion with the given components. | |
| Quaternion & | operator= (double scalar) |
| Sets the scalar (real) part of the quaternion also clearing the vector part. | |
| static Quaternion | FromAxisAngle (double angle, double vx, double vy, double vz) |
| Constructs a quaternion from axis angle representation of rotation. | |
Encapsulates Hamilton real quaternions.
Definition at line 25 of file Quaternion.h.
| WoRB::Quaternion::Quaternion | ( | ) | [inline] |
The default constructor; creates a zero quaternion.
Definition at line 50 of file Quaternion.h.
Referenced by ComponentWiseProduct(), Conjugate(), Cross(), FromAxisAngle(), operator*(), operator+(), operator-(), and Unit().
| WoRB::Quaternion::Quaternion | ( | double | scalar | ) | [inline] |
| WoRB::Quaternion::Quaternion | ( | double | w, |
| double | x, | ||
| double | y, | ||
| double | z | ||
| ) | [inline] |
| Quaternion WoRB::Quaternion::ComponentWiseProduct | ( | const Quaternion & | q | ) | const [inline] |
Returns a component-wise product of this and another quaternion.
Definition at line 290 of file Quaternion.h.
References Quaternion(), w, x, y, and z.
Referenced by WoRB::Cuboid::Check(), WoRB::Cuboid::RegisterContactOnAxis_Thorough(), and WoRB::Cuboid::SetMass().
{
return Quaternion( w * q.w, x * q.x, y * q.y, z * q.z);
}
| Quaternion WoRB::Quaternion::Conjugate | ( | ) | const [inline] |
Returns the conjugate of the quaternion.
Definition at line 173 of file Quaternion.h.
References Quaternion(), w, x, y, and z.
{
return Quaternion( w, -x, -y, -z );
}
| Quaternion WoRB::Quaternion::Cross | ( | const Quaternion & | q | ) | const [inline] |
Returns a vector product of the vector parts of this and another quaternion.
Definition at line 297 of file Quaternion.h.
References Quaternion(), x, y, and z.
Referenced by WoRB::RigidBody::CalculateDerivedQuantities(), WoRB::Cuboid::Check(), WoRB::Collision::GetImpulse(), WoRB::Collision::GetRelativeVelocity(), WoRB::Collision::ImpulseTransfer(), WoRB::CollisionResolver::ImpulseTransfers(), WoRB::Cuboid::Intersects(), WoRB::Collision::PositionProjection(), and WoRB::CollisionResolver::PositionProjections().
| double WoRB::Quaternion::Dot | ( | const Quaternion & | q | ) | const [inline] |
Returns a scalar product of the vector parts of this and another quaternion.
Definition at line 307 of file Quaternion.h.
Referenced by WoRB::RigidBody::CalculateDerivedQuantities(), WoRB::Sphere::Check(), WoRB::Cuboid::Check(), WoRB::Cuboid::FindContactPointOnEdges(), WoRB::Collision::GetBouncingVelocity(), WoRB::Cuboid::GetPenetrationOnAxis(), WoRB::Sphere::Intersects(), WoRB::Cuboid::Intersects(), WoRB::Collision::PositionProjection(), WoRB::CollisionResolver::PositionProjections(), WoRB::Cuboid::ProjectOn(), WoRB::Cuboid::RegisterContactOnAxis(), WoRB::Cuboid::RegisterContactOnAxis_Thorough(), and WoRB::WorldOfRigidBodies< 256, 1024 >::SolveODE().
| void Quaternion::Dump | ( | const char * | name | ) | const |
| static Quaternion WoRB::Quaternion::FromAxisAngle | ( | double | angle, |
| double | vx, | ||
| double | vy, | ||
| double | vz | ||
| ) | [inline, static] |
Constructs a quaternion from axis angle representation of rotation.
Definition at line 80 of file Quaternion.h.
References Quaternion().
Referenced by WoRB_TestBed::ReconfigureTestBed().
{
double norm = sqrt( vx * vx + vy * vy + vz * vz );
if ( norm == 0 ) {
return Quaternion( 1 );
}
double Re = cos( angle/2 );
double Im = sin( angle/2 ) / norm;
return Quaternion( Re, Im * vx, Im * vy, Im * vz );
}
| double WoRB::Quaternion::ImNorm | ( | ) | const [inline] |
Gets the magnitude of the vector part of this quaternion.
Definition at line 208 of file Quaternion.h.
References ImSquaredNorm().
Referenced by WoRB::Sphere::Check(), and WoRB::Collision::PositionProjection().
{
return sqrt( ImSquaredNorm () );
}
| double WoRB::Quaternion::ImSquaredNorm | ( | ) | const [inline] |
Gets the squared magnitude of the vector part of this quaternion.
Definition at line 194 of file Quaternion.h.
Referenced by WoRB::Cuboid::CheckOverlapOnAxis(), WoRB::Cuboid::FindContactPointOnEdges(), ImNorm(), WoRB::Sphere::Intersects(), WoRB::Cuboid::IsOverlapOnAxis(), WoRB::RenderStateVariables(), and Trim().
| double WoRB::Quaternion::Norm | ( | ) | const [inline] |
Gets the magnitude of this quaternion.
Definition at line 201 of file Quaternion.h.
References SquaredNorm().
Referenced by Normalize().
{
return sqrt( SquaredNorm () );
}
| Quaternion& WoRB::Quaternion::Normalize | ( | double | length = 1.0 | ) | [inline] |
Normalizes the quaternion to a given length.
Definition at line 121 of file Quaternion.h.
Referenced by WoRB::RigidBody::CalculateDerivedQuantities(), WoRB::Collision::FindOrthonormalBasisAtContactPoint(), WoRB::RandomQuaternion(), WoRB::RenderStateVariables(), and Trim().
| bool WoRB::Quaternion::operator!= | ( | const Quaternion & | q | ) | const [inline] |
Checks if the two vectors have non-identical components.
Definition at line 325 of file Quaternion.h.
{
return !( *this == q );
}
| Quaternion WoRB::Quaternion::operator* | ( | const Quaternion & | q | ) | const [inline] |
Multiplies the quaternion by the given quaternion.
Definition at line 256 of file Quaternion.h.
References Quaternion(), w, x, y, and z.
| Quaternion WoRB::Quaternion::operator* | ( | double | value | ) | const [inline] |
Returns a copy of this quaternion scaled the given scalar value.
Definition at line 275 of file Quaternion.h.
References Quaternion(), w, x, y, and z.
{
return Quaternion( w * value, x * value, y * value, z * value);
}
| Quaternion& WoRB::Quaternion::operator*= | ( | const Quaternion & | right | ) | [inline] |
Multiplies the quaternion by the given quaternion.
Definition at line 268 of file Quaternion.h.
{
return *this = *this * right;
}
| Quaternion& WoRB::Quaternion::operator*= | ( | double | value | ) | [inline] |
| Quaternion WoRB::Quaternion::operator+ | ( | const Quaternion & | q | ) | const [inline] |
Returns the value of the given quaternion added to this.
Definition at line 226 of file Quaternion.h.
References Quaternion(), w, x, y, and z.
{
return Quaternion( w + q.w, x + q.x, y + q.y, z + q.z );
}
| Quaternion& WoRB::Quaternion::operator+= | ( | const Quaternion & | q | ) | [inline] |
| Quaternion WoRB::Quaternion::operator- | ( | ) | const [inline] |
Flips signs of all the components of the quaternion.
Definition at line 166 of file Quaternion.h.
References Quaternion(), w, x, y, and z.
{
return Quaternion( -w, -x, -y, -z );
}
| Quaternion WoRB::Quaternion::operator- | ( | const Quaternion & | q | ) | const [inline] |
Returns the value of the given quaternion subtracted from this.
Definition at line 241 of file Quaternion.h.
References Quaternion(), w, x, y, and z.
{
return Quaternion( w - q.w, x - q.x, y - q.y, z - q.z );
}
| Quaternion WoRB::Quaternion::operator-= | ( | const Quaternion & | q | ) | [inline] |
| bool WoRB::Quaternion::operator< | ( | const Quaternion & | q | ) | const [inline] |
| bool WoRB::Quaternion::operator<= | ( | const Quaternion & | q | ) | const [inline] |
| Quaternion& WoRB::Quaternion::operator= | ( | double | scalar | ) | [inline] |
| bool WoRB::Quaternion::operator== | ( | const Quaternion & | q | ) | const [inline] |
| bool WoRB::Quaternion::operator> | ( | const Quaternion & | q | ) | const [inline] |
| bool WoRB::Quaternion::operator>= | ( | const Quaternion & | q | ) | const [inline] |
| double WoRB::Quaternion::operator[] | ( | unsigned | index | ) | const [inline] |
| double& WoRB::Quaternion::operator[] | ( | unsigned | index | ) | [inline] |
| double WoRB::Quaternion::ReSquaredNorm | ( | ) | const [inline] |
Gets the squared magnitude of the scalar part of this quaternion.
Definition at line 187 of file Quaternion.h.
References w.
| double WoRB::Quaternion::SquaredNorm | ( | ) | const [inline] |
| Quaternion& WoRB::Quaternion::Trim | ( | double | size | ) | [inline] |
Limits the size of the quaternion to the given maximum.
Definition at line 138 of file Quaternion.h.
References ImSquaredNorm(), and Normalize().
{
if ( ImSquaredNorm () > size * size )
{
return Normalize( size );
}
return *this;
}
| Quaternion WoRB::Quaternion::Unit | ( | double | length = 1.0 | ) | const [inline] |
Returns the normalized version (versor) of a quaternion.
Definition at line 215 of file Quaternion.h.
References Quaternion().
Referenced by WoRB::Cuboid::Check(), and WoRB::Cuboid::GetPenetrationOnAxis().
{
return Quaternion( *this ).Normalize( length );
}
| Quaternion& WoRB::Quaternion::Zeroize | ( | double | eps = 1e-4 | ) | [inline] |
| double WoRB::Quaternion::w |
Holds the real (scalar) part of the quaternion.
Definition at line 39 of file Quaternion.h.
Referenced by ComponentWiseProduct(), Conjugate(), WoRB_TestBed::Dump(), Dump(), Normalize(), operator*(), WoRB::operator*(), operator*=(), operator+(), WoRB::operator+(), operator+=(), operator-(), WoRB::operator-(), operator-=(), operator<(), operator<=(), operator=(), operator==(), operator>(), operator>=(), operator[](), WoRB::QTensor::QTensor(), WoRB::RandomQuaternion(), WoRB_TestBed::ReconfigureTestBed(), WoRB_TestBed::RenderDebugInfo(), ReSquaredNorm(), WoRB::QTensor::SetFromOrientationAndPosition(), WoRB::QTensor::SetLeftMultiplier(), WoRB::QTensor::SetRightMultiplier(), SquaredNorm(), and Zeroize().
| double WoRB::Quaternion::x |
Holds i-component of the pure imaginary (vector) part.
Definition at line 40 of file Quaternion.h.
Referenced by WoRB::Box::Box(), WoRB::Cuboid::Check(), ComponentWiseProduct(), Conjugate(), Cross(), Dot(), WoRB_TestBed::Dump(), Dump(), WoRB::Collision::FindOrthonormalBasisAtContactPoint(), WoRB::Collision::GetBouncingVelocity(), WoRB::Collision::GetImpulse_IncludeFriction(), WoRB::Collision::GetRelativeVelocity(), ImSquaredNorm(), WoRB_MexFunction::OnProcessData(), WoRB::QTensor::operator()(), operator*(), WoRB::QTensor::operator*(), WoRB::operator*(), operator*=(), operator+(), WoRB::operator+(), operator+=(), operator-(), WoRB::operator-(), operator-=(), operator<(), operator<=(), operator=(), operator==(), operator>(), operator>=(), operator[](), WoRB::Cuboid::ProjectOn(), WoRB::QTensor::QTensor(), WoRB::RandomQuaternion(), WoRB::Box::Render(), WoRB_TestBed::RenderDebugInfo(), WoRB::RenderStateVariables(), WoRB::Box::RenderWireframe(), WoRB::QTensor::SetColumnVectors(), WoRB::QTensor::SetFromOrientationAndPosition(), WoRB::QTensor::SetLeftMultiplier(), WoRB::Cuboid::SetMass(), WoRB::QTensor::SetRightMultiplier(), WoRB::QTensor::SetSkewSymmetric(), SquaredNorm(), WoRB::QTensor::TransformInverse(), WoRB::Cuboid::Volume(), and Zeroize().
| double WoRB::Quaternion::y |
Holds j-component of the pure imaginary (vector) part.
Definition at line 41 of file Quaternion.h.
Referenced by WoRB::Box::Box(), WoRB::Cuboid::Check(), ComponentWiseProduct(), Conjugate(), Cross(), Dot(), WoRB_TestBed::Dump(), Dump(), WoRB::Collision::FindOrthonormalBasisAtContactPoint(), WoRB::Collision::GetImpulse_IncludeFriction(), ImSquaredNorm(), WoRB_MexFunction::OnProcessData(), WoRB::QTensor::operator()(), operator*(), WoRB::QTensor::operator*(), WoRB::operator*(), operator*=(), operator+(), WoRB::operator+(), operator+=(), operator-(), WoRB::operator-(), operator-=(), operator<(), operator<=(), operator=(), operator==(), operator>(), operator>=(), WoRB::Cuboid::ProjectOn(), WoRB::QTensor::QTensor(), WoRB::RandomQuaternion(), WoRB_TestBed::ReconfigureTestBed(), WoRB::Box::Render(), WoRB_TestBed::RenderDebugInfo(), WoRB::RenderStateVariables(), WoRB::Box::RenderWireframe(), WoRB::QTensor::SetColumnVectors(), WoRB::QTensor::SetFromOrientationAndPosition(), WoRB::QTensor::SetLeftMultiplier(), WoRB::Cuboid::SetMass(), WoRB::QTensor::SetRightMultiplier(), WoRB::QTensor::SetSkewSymmetric(), SquaredNorm(), WoRB::QTensor::TransformInverse(), WoRB::Cuboid::Volume(), and Zeroize().
| double WoRB::Quaternion::z |
Holds k-component of the pure imaginary (vector) part.
Definition at line 42 of file Quaternion.h.
Referenced by WoRB::Box::Box(), WoRB::Cuboid::Check(), ComponentWiseProduct(), Conjugate(), Cross(), Dot(), WoRB_TestBed::Dump(), Dump(), WoRB::Collision::FindOrthonormalBasisAtContactPoint(), WoRB::Collision::GetImpulse_IncludeFriction(), ImSquaredNorm(), WoRB_MexFunction::OnProcessData(), WoRB::QTensor::operator()(), operator*(), WoRB::QTensor::operator*(), WoRB::operator*(), operator*=(), operator+(), WoRB::operator+(), operator+=(), operator-(), WoRB::operator-(), operator-=(), operator<(), operator<=(), operator=(), operator==(), operator>(), operator>=(), WoRB::Cuboid::ProjectOn(), WoRB::QTensor::QTensor(), WoRB::RandomQuaternion(), WoRB::Box::Render(), WoRB_TestBed::RenderDebugInfo(), WoRB::RenderStateVariables(), WoRB::Box::RenderWireframe(), WoRB::QTensor::SetColumnVectors(), WoRB::QTensor::SetFromOrientationAndPosition(), WoRB::QTensor::SetLeftMultiplier(), WoRB::Cuboid::SetMass(), WoRB::QTensor::SetRightMultiplier(), WoRB::QTensor::SetSkewSymmetric(), SquaredNorm(), WoRB::QTensor::TransformInverse(), WoRB::Cuboid::Volume(), and Zeroize().