50 #include "FGMatrix33.h" 51 #include "FGColumnVector3.h" 53 #include "FGQuaternion.h" 61 IDENT(IdSrc,
"$Id: FGQuaternion.cpp,v 1.24 2014/01/13 10:46:03 ehofman Exp $");
62 IDENT(IdHdr,ID_QUATERNION);
76 mEulerAngles = q.mEulerAngles;
77 mEulerSines = q.mEulerSines;
78 mEulerCosines = q.mEulerCosines;
87 InitializeFromEulerAngles(phi, tht, psi);
94 double phi = vOrient(ePhi);
95 double tht = vOrient(eTht);
96 double psi = vOrient(ePsi);
98 InitializeFromEulerAngles(phi, tht, psi);
109 void FGQuaternion::InitializeFromEulerAngles(
double phi,
double tht,
double psi)
111 mEulerAngles(ePhi) = phi;
112 mEulerAngles(eTht) = tht;
113 mEulerAngles(ePsi) = psi;
115 double thtd2 = 0.5*tht;
116 double psid2 = 0.5*psi;
117 double phid2 = 0.5*phi;
119 double Sthtd2 = sin(thtd2);
120 double Spsid2 = sin(psid2);
121 double Sphid2 = sin(phid2);
123 double Cthtd2 = cos(thtd2);
124 double Cpsid2 = cos(psid2);
125 double Cphid2 = cos(phid2);
127 double Cphid2Cthtd2 = Cphid2*Cthtd2;
128 double Cphid2Sthtd2 = Cphid2*Sthtd2;
129 double Sphid2Sthtd2 = Sphid2*Sthtd2;
130 double Sphid2Cthtd2 = Sphid2*Cthtd2;
132 data[0] = Cphid2Cthtd2*Cpsid2 + Sphid2Sthtd2*Spsid2;
133 data[1] = Sphid2Cthtd2*Cpsid2 - Cphid2Sthtd2*Spsid2;
134 data[2] = Cphid2Sthtd2*Cpsid2 + Sphid2Cthtd2*Spsid2;
135 data[3] = Cphid2Cthtd2*Spsid2 - Sphid2Sthtd2*Cpsid2;
144 data[0] = 0.50*sqrt(1.0 + m(1,1) + m(2,2) + m(3,3));
145 double t = 0.25/data[0];
146 data[1] = t*(m(2,3) - m(3,2));
147 data[2] = t*(m(3,1) - m(1,3));
148 data[3] = t*(m(1,2) - m(2,1));
164 -0.5*( data[1]*PQR(eP) + data[2]*PQR(eQ) + data[3]*PQR(eR)),
165 0.5*( data[0]*PQR(eP) - data[3]*PQR(eQ) + data[2]*PQR(eR)),
166 0.5*( data[3]*PQR(eP) + data[0]*PQR(eQ) - data[1]*PQR(eR)),
167 0.5*(-data[2]*PQR(eP) + data[1]*PQR(eQ) + data[0]*PQR(eR))
177 if (norm == 0.0 || fabs(norm - 1.000) < 1e-10)
return;
179 double rnorm = 1.0/norm;
190 void FGQuaternion::ComputeDerivedUnconditional(
void)
const 211 mT(1,1) = q0q0 + q1q1 - q2q2 - q3q3;
212 mT(1,2) = 2.0*(q1q2 + q0q3);
213 mT(1,3) = 2.0*(q1q3 - q0q2);
214 mT(2,1) = 2.0*(q1q2 - q0q3);
215 mT(2,2) = q0q0 - q1q1 + q2q2 - q3q3;
216 mT(2,3) = 2.0*(q2q3 + q0q1);
217 mT(3,1) = 2.0*(q1q3 + q0q2);
218 mT(3,2) = 2.0*(q2q3 - q0q1);
219 mT(3,3) = q0q0 - q1q1 - q2q2 + q3q3;
231 mEulerSines(ePhi) = sin(mEulerAngles(ePhi));
233 mEulerSines(eTht) = -mT(1,3);
234 mEulerSines(ePsi) = sin(mEulerAngles(ePsi));
235 mEulerCosines(ePhi) = cos(mEulerAngles(ePhi));
236 mEulerCosines(eTht) = cos(mEulerAngles(eTht));
237 mEulerCosines(ePsi) = cos(mEulerAngles(ePsi));
242 std::string FGQuaternion::Dump(
const std::string& delimiter)
const 244 std::ostringstream buffer;
245 buffer << std::setprecision(16) << data[0] << delimiter;
246 buffer << std::setprecision(16) << data[1] << delimiter;
247 buffer << std::setprecision(16) << data[2] << delimiter;
248 buffer << std::setprecision(16) << data[3];
254 std::ostream& operator<<(std::ostream& os,
const FGQuaternion& q)
256 os << q(1) <<
" , " << q(2) <<
" , " << q(3) <<
" , " << q(4);
Models the Quaternion representation of rotations.
FGQuaternion GetQDot(const FGColumnVector3 &PQR) const
Quaternion derivative for given angular rates.
FGColumnVector3 GetEuler() const
Returns the Euler angle column vector associated with this matrix.
double Magnitude(void) const
Length of the vector.
FGQuaternion()
Default initializer.
This class implements a 3 element column vector.
void T(void)
Transposes this matrix.
Handles matrix math operations.
void Normalize(void)
Normalize.