![]() |
JSBSim Flight Dynamics Model 1.0 (23 February 2013)
An Open Source Flight Dynamics and Control Software Library in C++
|
Models the Quaternion representation of rotations. More...
#include <FGQuaternion.h>
Inheritance diagram for FGQuaternion:
Collaboration diagram for FGQuaternion:Public Member Functions | |
| FGQuaternion () | |
| Default initializer. | |
| FGQuaternion (const FGQuaternion &q) | |
| Copy constructor. | |
| FGQuaternion (FGColumnVector3 vOrient) | |
| Initializer by euler angle vector. | |
| FGQuaternion (int idx, double angle) | |
| Initializer by one euler angle. | |
| FGQuaternion (double phi, double tht, double psi) | |
| Initializer by euler angles. | |
| FGQuaternion (const FGMatrix33 &m) | |
| Initializer by matrix. | |
| ~FGQuaternion () | |
| Destructor. | |
| FGQuaternion | Conjugate (void) const |
| Conjugate of the quaternion. | |
| std::string | Dump (const std::string &delimiter) const |
| double | Entry (unsigned int idx) const |
| Read access the entries of the vector. | |
| double & | Entry (unsigned int idx) |
| Write access the entries of the vector. | |
| double | GetCosEuler (int i) const |
| Retrieves cosine of the given euler angle. | |
| const FGColumnVector3 & | GetEuler (void) const |
| Retrieves the Euler angles. | |
| double | GetEuler (int i) const |
| Retrieves the Euler angles. | |
| double | GetEulerDeg (int i) const |
| Retrieves the Euler angles. | |
| FGColumnVector3 const | GetEulerDeg (void) const |
| Retrieves the Euler angle vector. | |
| FGQuaternion | GetQDot (const FGColumnVector3 &PQR) const |
| Quaternion derivative for given angular rates. | |
| double | GetSinEuler (int i) const |
| Retrieves sine of the given euler angle. | |
| const FGMatrix33 & | GetT (void) const |
| Transformation matrix. | |
| const FGMatrix33 & | GetTInv (void) const |
| Backward transformation matrix. | |
| FGQuaternion | Inverse (void) const |
| Inverse of the quaternion. | |
| double | Magnitude (void) const |
| Length of the vector. | |
| void | Normalize (void) |
| Normalize. | |
| operator FGMatrix33 () const | |
| Conversion from Quat to Matrix. | |
| bool | operator!= (const FGQuaternion &q) const |
| Comparison operator "!=". | |
| double & | operator() (unsigned int idx) |
| Write access the entries of the vector. | |
| double | operator() (unsigned int idx) const |
| Read access the entries of the vector. | |
| FGQuaternion | operator* (const FGQuaternion &q) const |
| Arithmetic operator "*". | |
| const FGQuaternion & | operator*= (double scalar) |
| Arithmetic operator "*=". | |
| const FGQuaternion & | operator*= (const FGQuaternion &q) |
| Arithmetic operator "*=". | |
| FGQuaternion | operator+ (const FGQuaternion &q) const |
| Arithmetic operator "+". | |
| const FGQuaternion & | operator+= (const FGQuaternion &q) |
| FGQuaternion | operator- (const FGQuaternion &q) const |
| Arithmetic operator "-". | |
| const FGQuaternion & | operator-= (const FGQuaternion &q) |
| Arithmetic operator "-=". | |
| const FGQuaternion & | operator/= (double scalar) |
| Arithmetic operator "/=". | |
| const FGQuaternion & | operator= (const FGQuaternion &q) |
| Assignment operator "=". | |
| bool | operator== (const FGQuaternion &q) const |
| Comparison operator "==". | |
| double | SqrMagnitude (void) const |
| Square of the length of the vector. | |
Static Public Member Functions | |
| static FGQuaternion | zero (void) |
| Zero quaternion vector. | |
Friends | |
| FGQuaternion | operator* (double, const FGQuaternion &) |
| Scalar multiplication. | |
| FGQuaternion | QExp (const FGColumnVector3 &omega) |
| Quaternion exponential. | |
FGQuaternion is a representation of an arbitrary rotation through a quaternion. It has vector properties. This class also contains access functions to the euler angle representation of rotations and access to transformation matrices for 3D vectors. Transformations and euler angles are therefore computed once they are requested for the first time. Then they are cached for later usage as long as the class is not accessed trough a nonconst member function.
Note: The order of rotations used in this class corresponds to a 3-2-1 sequence, or Y-P-R, or Z-Y-X, if you prefer.
Definition at line 92 of file FGQuaternion.h.
| FGQuaternion | ( | ) | [inline] |
Default initializer, initializes the class with the identity rotation.
Definition at line 96 of file FGQuaternion.h.
Referenced by FGQuaternion::Conjugate(), FGQuaternion::GetQDot(), FGQuaternion::Inverse(), FGQuaternion::operator*(), FGQuaternion::operator+(), FGQuaternion::operator-(), and FGQuaternion::zero().
: mCacheValid(false) {
data[0] = 1.0;
data[1] = data[2] = data[3] = 0.0;
}
Here is the caller graph for this function:| FGQuaternion | ( | const FGQuaternion & | q | ) |
Copy constructor, initializes the quaternion.
| q | a constant reference to another FGQuaternion instance |
Definition at line 67 of file FGQuaternion.cpp.
: mCacheValid(q.mCacheValid)
{
data[0] = q(1);
data[1] = q(2);
data[2] = q(3);
data[3] = q(4);
if (mCacheValid) {
mT = q.mT;
mTInv = q.mTInv;
mEulerAngles = q.mEulerAngles;
mEulerSines = q.mEulerSines;
mEulerCosines = q.mEulerCosines;
}
}
| FGQuaternion | ( | double | phi, |
| double | tht, | ||
| double | psi | ||
| ) |
Initialize the quaternion with the euler angles.
| phi | The euler X axis (roll) angle in radians |
| tht | The euler Y axis (attitude) angle in radians |
| psi | The euler Z axis (heading) angle in radians |
Definition at line 85 of file FGQuaternion.cpp.
: mCacheValid(false)
{
InitializeFromEulerAngles(phi, tht, psi);
}
| FGQuaternion | ( | FGColumnVector3 | vOrient | ) |
Initialize the quaternion with the euler angle vector.
| vOrient | The euler axis angle vector in radians (phi, tht, psi) |
Definition at line 92 of file FGQuaternion.cpp.
: mCacheValid(false) { double phi = vOrient(ePhi); double tht = vOrient(eTht); double psi = vOrient(ePsi); InitializeFromEulerAngles(phi, tht, psi); }
| FGQuaternion | ( | int | idx, |
| double | angle | ||
| ) | [inline] |
Initialize the quaternion with the single euler angle where its index is given in the first argument.
| idx | Index of the euler angle to initialize |
| angle | The euler angle in radians |
Definition at line 123 of file FGQuaternion.h.
: mCacheValid(false) { double angle2 = 0.5*angle; double Sangle2 = sin(angle2); double Cangle2 = cos(angle2); if (idx == ePhi) { data[0] = Cangle2; data[1] = Sangle2; data[2] = 0.0; data[3] = 0.0; } else if (idx == eTht) { data[0] = Cangle2; data[1] = 0.0; data[2] = Sangle2; data[3] = 0.0; } else { data[0] = Cangle2; data[1] = 0.0; data[2] = 0.0; data[3] = Sangle2; } }
| FGQuaternion | ( | const FGMatrix33 & | m | ) |
Initialize the quaternion with the matrix representing a transform from one frame to another using the standard aerospace sequence, Yaw-Pitch-Roll (3-2-1).
| m | the rotation matrix |
Definition at line 142 of file FGQuaternion.cpp.
References FGQuaternion::Normalize().
: mCacheValid(false) { data[0] = 0.50*sqrt(1.0 + m(1,1) + m(2,2) + m(3,3)); double t = 0.25/data[0]; data[1] = t*(m(2,3) - m(3,2)); data[2] = t*(m(3,1) - m(1,3)); data[3] = t*(m(1,2) - m(2,1)); Normalize(); }
Here is the call graph for this function:| FGQuaternion Conjugate | ( | void | ) | const [inline] |
Compute and return the conjugate of the quaternion. This one is equal to the inverse iff the quaternion is normalized.
Definition at line 435 of file FGQuaternion.h.
References FGQuaternion::FGQuaternion().
{
return FGQuaternion( data[0], -data[1], -data[2], -data[3] );
}
Here is the call graph for this function:| double Entry | ( | unsigned int | idx | ) | const [inline] |
| idx | the component index. |
Return the value of the matrix entry at the given index. Indices are counted starting with 1.
This function is just a shortcut for the double operator()(unsigned int idx) const function. It is used internally to access the elements in a more convenient way.
Note that the index given in the argument is unchecked.
Definition at line 270 of file FGQuaternion.h.
{ return data[idx-1]; }
| double& Entry | ( | unsigned int | idx | ) | [inline] |
| idx | the component index. |
Return a reference to the vector entry at the given index. Indices are counted starting with 1.
This function is just a shortcut for the double& operator()(unsigned int idx) function. It is used internally to access the elements in a more convenient way.
Note that the index given in the argument is unchecked.
Definition at line 285 of file FGQuaternion.h.
{
mCacheValid = false;
return data[idx-1];
}
| double GetCosEuler | ( | int | i | ) | const [inline] |
Definition at line 230 of file FGQuaternion.h.
Referenced by FGPropagate::GetCosEuler(), FGInitialCondition::SetBetaRadIC(), FGInitialCondition::SetCrossWindKtsIC(), FGInitialCondition::SetHeadWindKtsIC(), and FGInitialCondition::SetVgroundFpsIC().
{
ComputeDerived();
return mEulerCosines(i);
}
Here is the caller graph for this function:| const FGColumnVector3& GetEuler | ( | void | ) | const [inline] |
Definition at line 184 of file FGQuaternion.h.
Referenced by FGPropagate::GetEuler(), FGInitialCondition::GetPhiRadIC(), FGInitialCondition::GetPsiRadIC(), FGInitialCondition::GetThetaRadIC(), and FGInitialCondition::SetBetaRadIC().
{
ComputeDerived();
return mEulerAngles;
}
Here is the caller graph for this function:| double GetEuler | ( | int | i | ) | const [inline] |
| i | the Euler angle index. units radians. |
Definition at line 195 of file FGQuaternion.h.
{
ComputeDerived();
return mEulerAngles(i);
}
| double GetEulerDeg | ( | int | i | ) | const [inline] |
| i | the Euler angle index. |
Definition at line 205 of file FGQuaternion.h.
Referenced by FGInitialCondition::GetPhiDegIC(), FGInitialCondition::GetPsiDegIC(), and FGInitialCondition::GetThetaDegIC().
{
ComputeDerived();
return radtodeg*mEulerAngles(i);
}
Here is the caller graph for this function:| FGColumnVector3 const GetEulerDeg | ( | void | ) | const [inline] |
Definition at line 214 of file FGQuaternion.h.
{
ComputeDerived();
return radtodeg*mEulerAngles;
}
| FGQuaternion GetQDot | ( | const FGColumnVector3 & | PQR | ) | const |
Returns the derivative of the quaternion corresponding to the angular velocities PQR.
Computes the quaternion derivative which results from the given angular velocities
| PQR | a constant reference to a rotation rate vector |
See Stevens and Lewis, "Aircraft Control and Simulation", Second Edition, Equation 1.3-36. Also see Jack Kuipers, "Quaternions and Rotation Sequences", Equation 11.12.
Definition at line 161 of file FGQuaternion.cpp.
References FGQuaternion::FGQuaternion().
{
return FGQuaternion(
-0.5*( data[1]*PQR(eP) + data[2]*PQR(eQ) + data[3]*PQR(eR)),
0.5*( data[0]*PQR(eP) - data[3]*PQR(eQ) + data[2]*PQR(eR)),
0.5*( data[3]*PQR(eP) + data[0]*PQR(eQ) - data[1]*PQR(eR)),
0.5*(-data[2]*PQR(eP) + data[1]*PQR(eQ) + data[0]*PQR(eR))
);
}
Here is the call graph for this function:| double GetSinEuler | ( | int | i | ) | const [inline] |
Definition at line 222 of file FGQuaternion.h.
Referenced by FGPropagate::GetSinEuler(), FGInitialCondition::SetBetaRadIC(), FGInitialCondition::SetCrossWindKtsIC(), FGInitialCondition::SetHeadWindKtsIC(), and FGInitialCondition::SetVgroundFpsIC().
{
ComputeDerived();
return mEulerSines(i);
}
Here is the caller graph for this function:| const FGMatrix33& GetT | ( | void | ) | const [inline] |
Definition at line 173 of file FGQuaternion.h.
Referenced by FGInitialCondition::GetUVWFpsIC(), and FGQuaternion::operator FGMatrix33().
{ ComputeDerived(); return mT; }
Here is the caller graph for this function:| const FGMatrix33& GetTInv | ( | void | ) | const [inline] |
Definition at line 178 of file FGQuaternion.h.
Referenced by FGInitialCondition::GetClimbRateFpsIC(), FGInitialCondition::GetWindDirDegIC(), FGInitialCondition::GetWindFpsIC(), FGInitialCondition::GetWindNEDFpsIC(), FGInitialCondition::ResetIC(), FGInitialCondition::SetAlphaRadIC(), FGInitialCondition::SetBetaRadIC(), FGInitialCondition::SetClimbRateFpsIC(), FGInitialCondition::SetCrossWindKtsIC(), FGInitialCondition::SetHeadWindKtsIC(), FGInitialCondition::SetVgroundFpsIC(), FGInitialCondition::SetVtrueFpsIC(), FGInitialCondition::SetWindDirDegIC(), FGInitialCondition::SetWindDownKtsIC(), and FGInitialCondition::SetWindMagKtsIC().
{ ComputeDerived(); return mTInv; }
Here is the caller graph for this function:| FGQuaternion Inverse | ( | void | ) | const [inline] |
Compute and return the inverse of the quaternion so that the orientation represented with *this multiplied with the returned value is equal to the identity orientation.
Definition at line 421 of file FGQuaternion.h.
References FGQuaternion::FGQuaternion(), and FGQuaternion::SqrMagnitude().
{
double norm = SqrMagnitude();
if (norm == 0.0)
return *this;
double rNorm = 1.0/norm;
return FGQuaternion( data[0]*rNorm, -data[1]*rNorm,
-data[2]*rNorm, -data[3]*rNorm );
}
Here is the call graph for this function:| double Magnitude | ( | void | ) | const [inline] |
Compute and return the euclidean norm of this vector.
Definition at line 445 of file FGQuaternion.h.
References FGQuaternion::SqrMagnitude().
Referenced by FGQuaternion::Normalize().
{ return sqrt(SqrMagnitude()); }
Here is the call graph for this function:
Here is the caller graph for this function:| void Normalize | ( | void | ) |
Normalize the vector to have the Magnitude() == 1.0. If the vector is equal to zero it is left untouched.
Definition at line 173 of file FGQuaternion.cpp.
References FGQuaternion::Magnitude().
Referenced by FGQuaternion::FGQuaternion().
{
// Note: this does not touch the cache since it does not change the orientation
double norm = Magnitude();
if (norm == 0.0 || fabs(norm - 1.000) < 1e-10) return;
double rnorm = 1.0/norm;
data[0] *= rnorm;
data[1] *= rnorm;
data[2] *= rnorm;
data[3] *= rnorm;
}
Here is the call graph for this function:
Here is the caller graph for this function:| bool operator!= | ( | const FGQuaternion & | q | ) | const [inline] |
| q | a quaternion reference |
Definition at line 328 of file FGQuaternion.h.
References FGQuaternion::operator==().
{ return ! operator==(q); }
Here is the call graph for this function:| double operator() | ( | unsigned int | idx | ) | const [inline] |
| idx | the component index. |
Return the value of the matrix entry at the given index. Indices are counted starting with 1.
Note that the index given in the argument is unchecked.
Definition at line 244 of file FGQuaternion.h.
{ return data[idx-1]; }
| double& operator() | ( | unsigned int | idx | ) | [inline] |
| idx | the component index. |
Return a reference to the vector entry at the given index. Indices are counted starting with 1.
Note that the index given in the argument is unchecked.
Definition at line 255 of file FGQuaternion.h.
{ mCacheValid = false; return data[idx-1]; }
| FGQuaternion operator* | ( | const FGQuaternion & | q | ) | const [inline] |
Multiplication of two quaternions is like performing successive rotations.
| q | a quaternion to be multiplied. |
Definition at line 391 of file FGQuaternion.h.
References FGQuaternion::FGQuaternion().
{
return FGQuaternion(data[0]*q.data[0]-data[1]*q.data[1]-data[2]*q.data[2]-data[3]*q.data[3],
data[0]*q.data[1]+data[1]*q.data[0]+data[2]*q.data[3]-data[3]*q.data[2],
data[0]*q.data[2]-data[1]*q.data[3]+data[2]*q.data[0]+data[3]*q.data[1],
data[0]*q.data[3]+data[1]*q.data[2]-data[2]*q.data[1]+data[3]*q.data[0]);
}
Here is the call graph for this function:| const FGQuaternion& operator*= | ( | double | scalar | ) | [inline] |
| scalar | a multiplicative value. |
Definition at line 355 of file FGQuaternion.h.
Referenced by FGQuaternion::operator/=().
{
data[0] *= scalar;
data[1] *= scalar;
data[2] *= scalar;
data[3] *= scalar;
mCacheValid = false;
return *this;
}
Here is the caller graph for this function:| const FGQuaternion& operator*= | ( | const FGQuaternion & | q | ) | [inline] |
Multiplication of two quaternions is like performing successive rotations.
| q | a quaternion to be multiplied. |
Definition at line 402 of file FGQuaternion.h.
{
double q0 = data[0]*q.data[0]-data[1]*q.data[1]-data[2]*q.data[2]-data[3]*q.data[3];
double q1 = data[0]*q.data[1]+data[1]*q.data[0]+data[2]*q.data[3]-data[3]*q.data[2];
double q2 = data[0]*q.data[2]-data[1]*q.data[3]+data[2]*q.data[0]+data[3]*q.data[1];
double q3 = data[0]*q.data[3]+data[1]*q.data[2]-data[2]*q.data[1]+data[3]*q.data[0];
data[0] = q0;
data[1] = q1;
data[2] = q2;
data[3] = q3;
mCacheValid = false;
return *this;
}
| FGQuaternion operator+ | ( | const FGQuaternion & | q | ) | const [inline] |
| q | a quaternion to be summed. |
Definition at line 374 of file FGQuaternion.h.
References FGQuaternion::FGQuaternion().
{
return FGQuaternion(data[0]+q.data[0], data[1]+q.data[1],
data[2]+q.data[2], data[3]+q.data[3]);
}
Here is the call graph for this function:| FGQuaternion operator- | ( | const FGQuaternion & | q | ) | const [inline] |
| q | a quaternion to be subtracted. |
Definition at line 382 of file FGQuaternion.h.
References FGQuaternion::FGQuaternion().
{
return FGQuaternion(data[0]-q.data[0], data[1]-q.data[1],
data[2]-q.data[2], data[3]-q.data[3]);
}
Here is the call graph for this function:| const FGQuaternion& operator-= | ( | const FGQuaternion & | q | ) | [inline] |
| q | a quaternion reference. |
Definition at line 342 of file FGQuaternion.h.
{
// Copy the master values ...
data[0] -= q.data[0];
data[1] -= q.data[1];
data[2] -= q.data[2];
data[3] -= q.data[3];
mCacheValid = false;
return *this;
}
| const FGQuaternion& operator/= | ( | double | scalar | ) | [inline] |
| scalar | a divisor value. |
Definition at line 367 of file FGQuaternion.h.
References FGQuaternion::operator*=().
{
return operator*=(1.0/scalar);
}
Here is the call graph for this function:| const FGQuaternion& operator= | ( | const FGQuaternion & | q | ) | [inline] |
Assign the value of q to the current object. Cached values are conserved.
| q | reference to an FGQuaternion instance |
Definition at line 295 of file FGQuaternion.h.
{
// Copy the master values ...
data[0] = q.data[0];
data[1] = q.data[1];
data[2] = q.data[2];
data[3] = q.data[3];
ComputeDerived();
// .. and copy the derived values if they are valid
mCacheValid = q.mCacheValid;
if (mCacheValid) {
mT = q.mT;
mTInv = q.mTInv;
mEulerAngles = q.mEulerAngles;
mEulerSines = q.mEulerSines;
mEulerCosines = q.mEulerCosines;
}
return *this;
}
| bool operator== | ( | const FGQuaternion & | q | ) | const [inline] |
| q | a quaternion reference |
Definition at line 320 of file FGQuaternion.h.
Referenced by FGQuaternion::operator!=().
{
return data[0] == q.data[0] && data[1] == q.data[1]
&& data[2] == q.data[2] && data[3] == q.data[3];
}
Here is the caller graph for this function:| double SqrMagnitude | ( | void | ) | const [inline] |
Compute and return the square of the euclidean norm of this vector.
Definition at line 451 of file FGQuaternion.h.
Referenced by FGQuaternion::Inverse(), and FGQuaternion::Magnitude().
{
return data[0]*data[0] + data[1]*data[1]
+ data[2]*data[2] + data[3]*data[3];
}
Here is the caller graph for this function:| static FGQuaternion zero | ( | void | ) | [inline, static] |
Does not represent any orientation. Useful for initialization of increments
Definition at line 465 of file FGQuaternion.h.
References FGQuaternion::FGQuaternion().
{ return FGQuaternion( 0.0, 0.0, 0.0, 0.0 ); }
Here is the call graph for this function:| FGQuaternion operator* | ( | double | scalar, |
| const FGQuaternion & | q | ||
| ) | [friend] |
| scalar | scalar value to multiply with. |
| q | Vector to multiply. |
Multiply the Vector with a scalar value.
Definition at line 524 of file FGQuaternion.h.
{
return FGQuaternion(scalar*q.data[0], scalar*q.data[1], scalar*q.data[2], scalar*q.data[3]);
}
| FGQuaternion QExp | ( | const FGColumnVector3 & | omega | ) | [friend] |
| omega | rotation velocity Calculate the unit quaternion which is the result of the exponentiation of the vector 'omega'. |
Definition at line 533 of file FGQuaternion.h.
{
FGQuaternion qexp;
double angle = omega.Magnitude();
double sina_a = angle > 0.0 ? sin(angle)/angle : 1.0;
qexp.data[0] = cos(angle);
qexp.data[1] = omega(1) * sina_a;
qexp.data[2] = omega(2) * sina_a;
qexp.data[3] = omega(3) * sina_a;
return qexp;
}