36 #ifndef FGQUATERNION_H 37 #define FGQUATERNION_H 44 #include "FGJSBBase.h" 45 #include "FGColumnVector3.h" 51 #define ID_QUATERNION "$Id: FGQuaternion.h,v 1.26 2013/11/24 16:53:15 bcoconni Exp $" 98 data[1] = data[2] = data[3] = 0.0;
124 : mCacheValid(false) {
126 double angle2 = 0.5*angle;
128 double Sangle2 = sin(angle2);
129 double Cangle2 = cos(angle2);
137 }
else if (idx == eTht) {
159 : mCacheValid(false) {
161 double angle2 = 0.5 * angle;
164 double Sangle2 = sin(angle2) / length;
165 double Cangle2 = cos(angle2);
168 data[1] = Sangle2 * axis(1);
169 data[2] = Sangle2 * axis(2);
170 data[3] = Sangle2 * axis(3);
218 return mEulerAngles(i);
228 return radtodeg*mEulerAngles(i);
237 return radtodeg*mEulerAngles;
245 return mEulerSines(i);
253 return mEulerCosines(i);
265 double operator()(
unsigned int idx)
const {
return data[idx-1]; }
276 double&
operator()(
unsigned int idx) { mCacheValid =
false;
return data[idx-1]; }
291 double Entry(
unsigned int idx)
const {
return data[idx-1]; }
324 mCacheValid = q.mCacheValid;
328 mEulerAngles = q.mEulerAngles;
329 mEulerSines = q.mEulerSines;
330 mEulerCosines = q.mEulerCosines;
342 return data[0] == q.data[0] && data[1] == q.data[1]
343 && data[2] == q.data[2] && data[3] == q.data[3];
352 data[0] += q.data[0];
353 data[1] += q.data[1];
354 data[2] += q.data[2];
355 data[3] += q.data[3];
365 data[0] -= q.data[0];
366 data[1] -= q.data[1];
367 data[2] -= q.data[2];
368 data[3] -= q.data[3];
396 return FGQuaternion(data[0]+q.data[0], data[1]+q.data[1],
397 data[2]+q.data[2], data[3]+q.data[3]);
404 return FGQuaternion(data[0]-q.data[0], data[1]-q.data[1],
405 data[2]-q.data[2], data[3]-q.data[3]);
413 return FGQuaternion(data[0]*q.data[0]-data[1]*q.data[1]-data[2]*q.data[2]-data[3]*q.data[3],
414 data[0]*q.data[1]+data[1]*q.data[0]+data[2]*q.data[3]-data[3]*q.data[2],
415 data[0]*q.data[2]-data[1]*q.data[3]+data[2]*q.data[0]+data[3]*q.data[1],
416 data[0]*q.data[3]+data[1]*q.data[2]-data[2]*q.data[1]+data[3]*q.data[0]);
424 double q0 = data[0]*q.data[0]-data[1]*q.data[1]-data[2]*q.data[2]-data[3]*q.data[3];
425 double q1 = data[0]*q.data[1]+data[1]*q.data[0]+data[2]*q.data[3]-data[3]*q.data[2];
426 double q2 = data[0]*q.data[2]-data[1]*q.data[3]+data[2]*q.data[0]+data[3]*q.data[1];
427 double q3 = data[0]*q.data[3]+data[1]*q.data[2]-data[2]*q.data[1]+data[3]*q.data[0];
446 double rNorm = 1.0/norm;
448 -data[2]*rNorm, -data[3]*rNorm );
457 return FGQuaternion( data[0], -data[1], -data[2], -data[3] );
473 return data[0]*data[0] + data[1]*data[1]
474 + data[2]*data[2] + data[3]*data[3];
488 std::string Dump(
const std::string& delimiter)
const;
494 FGQuaternion(
double q1,
double q2,
double q3,
double q4) : mCacheValid(
false)
495 { data[0] = q1; data[1] = q2; data[2] = q3; data[3] = q4; }
500 void ComputeDerivedUnconditional(
void)
const;
508 void ComputeDerived(
void)
const {
510 ComputeDerivedUnconditional();
522 mutable bool mCacheValid;
535 void InitializeFromEulerAngles(
double phi,
double tht,
double psi);
546 return FGQuaternion(scalar*q.data[0], scalar*q.data[1], scalar*q.data[2], scalar*q.data[3]);
557 double sina_a = angle > 0.0 ? sin(angle)/angle : 1.0;
559 qexp.data[0] = cos(angle);
560 qexp.data[1] = omega(1) * sina_a;
561 qexp.data[2] = omega(2) * sina_a;
562 qexp.data[3] = omega(3) * sina_a;
571 std::ostream& operator<<(std::ostream& os,
const FGQuaternion& q);
FGQuaternion(int idx, double angle)
Initializer by one euler angle.
Models the Quaternion representation of rotations.
double & operator()(unsigned int idx)
Write access the entries of the vector.
FGQuaternion GetQDot(const FGColumnVector3 &PQR) const
Quaternion derivative for given angular rates.
double Magnitude(void) const
Length of the vector.
const FGMatrix33 & GetT(void) const
Transformation matrix.
const FGQuaternion & operator=(const FGQuaternion &q)
Assignment operator "=".
double GetEulerDeg(int i) const
Retrieves the Euler angles.
double GetSinEuler(int i) const
Retrieves sine of the given euler angle.
FGQuaternion(double angle, const FGColumnVector3 &axis)
Initializer by a rotation axis and an angle.
const FGQuaternion & operator*=(double scalar)
Arithmetic operator "*=".
FGQuaternion()
Default initializer.
double Entry(unsigned int idx) const
Read access the entries of the vector.
const FGMatrix33 & GetTInv(void) const
Backward transformation matrix.
~FGQuaternion()
Destructor.
const FGQuaternion & operator/=(double scalar)
Arithmetic operator "/=".
friend FGQuaternion QExp(const FGColumnVector3 &omega)
Quaternion exponential.
const FGQuaternion & operator*=(const FGQuaternion &q)
Arithmetic operator "*=".
FGQuaternion Conjugate(void) const
Conjugate of the quaternion.
FGQuaternion operator+(const FGQuaternion &q) const
Arithmetic operator "+".
double SqrMagnitude(void) const
Square of the length of the vector.
double GetEuler(int i) const
Retrieves the Euler angles.
double & Entry(unsigned int idx)
Write access the entries of the vector.
This class implements a 3 element column vector.
FGQuaternion Inverse(void) const
Inverse of the quaternion.
FGQuaternion operator*(const FGQuaternion &q) const
Arithmetic operator "*".
bool operator==(const FGQuaternion &q) const
Comparison operator "==".
double operator()(unsigned int idx) const
Read access the entries of the vector.
double GetCosEuler(int i) const
Retrieves cosine of the given euler angle.
Handles matrix math operations.
FGColumnVector3 const GetEulerDeg(void) const
Retrieves the Euler angle vector.
double Magnitude(void) const
Length of the vector.
void Normalize(void)
Normalize.
const FGColumnVector3 & GetEuler(void) const
Retrieves the Euler angles.
static FGQuaternion zero(void)
Zero quaternion vector.
const FGQuaternion & operator-=(const FGQuaternion &q)
Arithmetic operator "-=".
FGQuaternion operator-(const FGQuaternion &q) const
Arithmetic operator "-".
bool operator!=(const FGQuaternion &q) const
Comparison operator "!=".