47#include "FGMatrix33.h"
48#include "FGColumnVector3.h"
50#include "FGQuaternion.h"
70 mEulerAngles = q.mEulerAngles;
71 mEulerSines = q.mEulerSines;
72 mEulerCosines = q.mEulerCosines;
81 InitializeFromEulerAngles(phi, tht, psi);
88 double phi = vOrient(ePhi);
89 double tht = vOrient(eTht);
90 double psi = vOrient(ePsi);
92 InitializeFromEulerAngles(phi, tht, psi);
103void FGQuaternion::InitializeFromEulerAngles(
double phi,
double tht,
double psi)
105 mEulerAngles(ePhi) = phi;
106 mEulerAngles(eTht) = tht;
107 mEulerAngles(ePsi) = psi;
109 double thtd2 = 0.5*tht;
110 double psid2 = 0.5*psi;
111 double phid2 = 0.5*phi;
113 double Sthtd2 = sin(thtd2);
114 double Spsid2 = sin(psid2);
115 double Sphid2 = sin(phid2);
117 double Cthtd2 = cos(thtd2);
118 double Cpsid2 = cos(psid2);
119 double Cphid2 = cos(phid2);
121 double Cphid2Cthtd2 = Cphid2*Cthtd2;
122 double Cphid2Sthtd2 = Cphid2*Sthtd2;
123 double Sphid2Sthtd2 = Sphid2*Sthtd2;
124 double Sphid2Cthtd2 = Sphid2*Cthtd2;
126 data[0] = Cphid2Cthtd2*Cpsid2 + Sphid2Sthtd2*Spsid2;
127 data[1] = Sphid2Cthtd2*Cpsid2 - Cphid2Sthtd2*Spsid2;
128 data[2] = Cphid2Sthtd2*Cpsid2 + Sphid2Cthtd2*Spsid2;
129 data[3] = Cphid2Cthtd2*Spsid2 - Sphid2Sthtd2*Cpsid2;
138 data[0] = 0.50*sqrt(1.0 + m(1,1) + m(2,2) + m(3,3));
139 double t = 0.25/data[0];
140 data[1] = t*(m(2,3) - m(3,2));
141 data[2] = t*(m(3,1) - m(1,3));
142 data[3] = t*(m(1,2) - m(2,1));
158 -0.5*( data[1]*PQR(eP) + data[2]*PQR(eQ) + data[3]*PQR(eR)),
159 0.5*( data[0]*PQR(eP) - data[3]*PQR(eQ) + data[2]*PQR(eR)),
160 0.5*( data[3]*PQR(eP) + data[0]*PQR(eQ) - data[1]*PQR(eR)),
161 0.5*(-data[2]*PQR(eP) + data[1]*PQR(eQ) + data[0]*PQR(eR))
171 if (norm == 0.0 || fabs(norm - 1.000) < 1e-10)
return;
173 double rnorm = 1.0/norm;
184void FGQuaternion::ComputeDerivedUnconditional(
void)
const
205 mT(1,1) = q0q0 + q1q1 - q2q2 - q3q3;
206 mT(1,2) = 2.0*(q1q2 + q0q3);
207 mT(1,3) = 2.0*(q1q3 - q0q2);
208 mT(2,1) = 2.0*(q1q2 - q0q3);
209 mT(2,2) = q0q0 - q1q1 + q2q2 - q3q3;
210 mT(2,3) = 2.0*(q2q3 + q0q1);
211 mT(3,1) = 2.0*(q1q3 + q0q2);
212 mT(3,2) = 2.0*(q2q3 - q0q1);
213 mT(3,3) = q0q0 - q1q1 - q2q2 + q3q3;
225 mEulerSines(ePhi) = sin(mEulerAngles(ePhi));
227 mEulerSines(eTht) = -mT(1,3);
228 mEulerSines(ePsi) = sin(mEulerAngles(ePsi));
229 mEulerCosines(ePhi) = cos(mEulerAngles(ePhi));
230 mEulerCosines(eTht) = cos(mEulerAngles(eTht));
231 mEulerCosines(ePsi) = cos(mEulerAngles(ePsi));
236std::string FGQuaternion::Dump(
const std::string& delimiter)
const
238 std::ostringstream buffer;
239 buffer << std::setprecision(16) << data[0] << delimiter;
240 buffer << std::setprecision(16) << data[1] << delimiter;
241 buffer << std::setprecision(16) << data[2] << delimiter;
242 buffer << std::setprecision(16) << data[3];
250 os << q(1) <<
" , " << q(2) <<
" , " << q(3) <<
" , " << q(4);
This class implements a 3 element column vector.
Handles matrix math operations.
void T(void)
Transposes this matrix.
FGColumnVector3 GetEuler() const
Returns the Euler angle column vector associated with this matrix.
Models the Quaternion representation of rotations.
void Normalize(void)
Normalize.
double Magnitude(void) const
Length of the vector.
FGQuaternion GetQDot(const FGColumnVector3 &PQR) const
Quaternion derivative for given angular rates.
FGQuaternion()
Default initializer.
Main namespace for the JSBSim Flight Dynamics Model.
ostream & operator<<(ostream &os, const FGColumnVector3 &col)
Write vector to a stream.