40#include "FGMatrix33.h"
41#include "FGColumnVector3.h"
42#include "FGQuaternion.h"
60 data[0] = data[1] = data[2] = data[3] = data[4] = data[5] =
61 data[6] = data[7] = data[8] = 0.0;
69 buffer << setw(12) << setprecision(10) << data[0] << delimiter;
70 buffer << setw(12) << setprecision(10) << data[3] << delimiter;
71 buffer << setw(12) << setprecision(10) << data[6] << delimiter;
72 buffer << setw(12) << setprecision(10) << data[1] << delimiter;
73 buffer << setw(12) << setprecision(10) << data[4] << delimiter;
74 buffer << setw(12) << setprecision(10) << data[7] << delimiter;
75 buffer << setw(12) << setprecision(10) << data[2] << delimiter;
76 buffer << setw(12) << setprecision(10) << data[5] << delimiter;
77 buffer << setw(12) << setprecision(10) << data[8];
87 buffer << prefix << right << fixed << setw(9) << setprecision(6) << data[0] << delimiter;
88 buffer << right << fixed << setw(9) << setprecision(6) << data[3] << delimiter;
89 buffer << right << fixed << setw(9) << setprecision(6) << data[6] << endl;
91 buffer << prefix << right << fixed << setw(9) << setprecision(6) << data[1] << delimiter;
92 buffer << right << fixed << setw(9) << setprecision(6) << data[4] << delimiter;
93 buffer << right << fixed << setw(9) << setprecision(6) << data[7] << endl;
95 buffer << prefix << right << fixed << setw(9) << setprecision(6) << data[2] << delimiter;
96 buffer << right << fixed << setw(9) << setprecision(6) << data[5] << delimiter;
97 buffer << right << fixed << setw(9) << setprecision(6) << data[8];
99 buffer << setw(0) << left;
113 tempQ[0] = 1.0 + data[0] + data[4] + data[8];
114 tempQ[1] = 1.0 + data[0] - data[4] - data[8];
115 tempQ[2] = 1.0 - data[0] + data[4] - data[8];
116 tempQ[3] = 1.0 - data[0] - data[4] + data[8];
120 for (
int i=1; i<4; i++)
if (tempQ[i] > tempQ[idx]) idx = i;
124 Q(1) = 0.50*sqrt(tempQ[0]);
125 Q(2) = 0.25*(data[7] - data[5])/Q(1);
126 Q(3) = 0.25*(data[2] - data[6])/Q(1);
127 Q(4) = 0.25*(data[3] - data[1])/Q(1);
130 Q(2) = 0.50*sqrt(tempQ[1]);
131 Q(1) = 0.25*(data[7] - data[5])/Q(2);
132 Q(3) = 0.25*(data[3] + data[1])/Q(2);
133 Q(4) = 0.25*(data[2] + data[6])/Q(2);
136 Q(3) = 0.50*sqrt(tempQ[2]);
137 Q(1) = 0.25*(data[2] - data[6])/Q(3);
138 Q(2) = 0.25*(data[3] + data[1])/Q(3);
139 Q(4) = 0.25*(data[7] + data[5])/Q(3);
142 Q(4) = 0.50*sqrt(tempQ[3]);
143 Q(1) = 0.25*(data[3] - data[1])/Q(4);
144 Q(2) = 0.25*(data[6] + data[2])/Q(4);
145 Q(3) = 0.25*(data[7] + data[5])/Q(4);
162 bool GimbalLock =
false;
164 if (data[6] <= -1.0) {
165 mEulerAngles(2) = 0.5*M_PI;
168 else if (1.0 <= data[6]) {
169 mEulerAngles(2) = -0.5*M_PI;
173 mEulerAngles(2) = asin(-data[6]);
176 mEulerAngles(1) = atan2(-data[5], data[4]);
178 mEulerAngles(1) = atan2(data[7], data[8]);
181 mEulerAngles(3) = 0.0;
183 double psi = atan2(data[3], data[0]);
186 mEulerAngles(3) = psi;
194ostream& operator<<(ostream& os,
const FGMatrix33& M)
196 for (
unsigned int i=1; i<=M.
Rows(); i++) {
197 for (
unsigned int j=1; j<=M.
Cols(); j++) {
201 os << M(i,j) <<
", ";
209istream& operator>>(istream& is, FGMatrix33& M)
211 for (
unsigned int i=1; i<=M.Rows(); i++) {
212 for (
unsigned int j=1; j<=M.Cols(); j++) {
222 return data[0]*data[4]*data[8] + data[3]*data[7]*data[2]
223 + data[6]*data[1]*data[5] - data[6]*data[4]*data[2]
224 - data[3]*data[1]*data[8] - data[7]*data[5]*data[0];
237 double i11 = rdet*(data[4]*data[8]-data[7]*data[5]);
238 double i21 = rdet*(data[7]*data[2]-data[1]*data[8]);
239 double i31 = rdet*(data[1]*data[5]-data[4]*data[2]);
240 double i12 = rdet*(data[6]*data[5]-data[3]*data[8]);
241 double i22 = rdet*(data[0]*data[8]-data[6]*data[2]);
242 double i32 = rdet*(data[3]*data[2]-data[0]*data[5]);
243 double i13 = rdet*(data[3]*data[7]-data[6]*data[4]);
244 double i23 = rdet*(data[6]*data[1]-data[0]*data[7]);
245 double i33 = rdet*(data[0]*data[4]-data[3]*data[1]);
261 data[0] = data[1] = data[2] = data[3] = data[4] = data[5] =
262 data[6] = data[7] = data[8] = 0.0;
279 data[8] - M.data[8] );
286 data[0] -= M.data[0];
287 data[1] -= M.data[1];
288 data[2] -= M.data[2];
289 data[3] -= M.data[3];
290 data[4] -= M.data[4];
291 data[5] -= M.data[5];
292 data[6] -= M.data[6];
293 data[7] -= M.data[7];
294 data[8] -= M.data[8];
311 data[8] + M.data[8] );
318 data[0] += M.data[0];
319 data[3] += M.data[3];
320 data[6] += M.data[6];
321 data[1] += M.data[1];
322 data[4] += M.data[4];
323 data[7] += M.data[7];
324 data[2] += M.data[2];
325 data[5] += M.data[5];
326 data[8] += M.data[8];
384 Product.data[0] = data[0]*M.data[0] + data[3]*M.data[1] + data[6]*M.data[2];
385 Product.data[3] = data[0]*M.data[3] + data[3]*M.data[4] + data[6]*M.data[5];
386 Product.data[6] = data[0]*M.data[6] + data[3]*M.data[7] + data[6]*M.data[8];
387 Product.data[1] = data[1]*M.data[0] + data[4]*M.data[1] + data[7]*M.data[2];
388 Product.data[4] = data[1]*M.data[3] + data[4]*M.data[4] + data[7]*M.data[5];
389 Product.data[7] = data[1]*M.data[6] + data[4]*M.data[7] + data[7]*M.data[8];
390 Product.data[2] = data[2]*M.data[0] + data[5]*M.data[1] + data[8]*M.data[2];
391 Product.data[5] = data[2]*M.data[3] + data[5]*M.data[4] + data[8]*M.data[5];
392 Product.data[8] = data[2]*M.data[6] + data[5]*M.data[7] + data[8]*M.data[8];
404 a = data[0]; b=data[3]; c=data[6];
405 data[0] = a*M.data[0] + b*M.data[1] + c*M.data[2];
406 data[3] = a*M.data[3] + b*M.data[4] + c*M.data[5];
407 data[6] = a*M.data[6] + b*M.data[7] + c*M.data[8];
409 a = data[1]; b=data[4]; c=data[7];
410 data[1] = a*M.data[0] + b*M.data[1] + c*M.data[2];
411 data[4] = a*M.data[3] + b*M.data[4] + c*M.data[5];
412 data[7] = a*M.data[6] + b*M.data[7] + c*M.data[8];
414 a = data[2]; b=data[5]; c=data[8];
415 data[2] = a*M.data[0] + b*M.data[1] + c*M.data[2];
416 data[5] = a*M.data[3] + b*M.data[4] + c*M.data[5];
417 data[8] = a*M.data[6] + b*M.data[7] + c*M.data[8];
428 double tmp = 1.0/scalar;
429 Quot.data[0] = data[0] * tmp;
430 Quot.data[3] = data[3] * tmp;
431 Quot.data[6] = data[6] * tmp;
432 Quot.data[1] = data[1] * tmp;
433 Quot.data[4] = data[4] * tmp;
434 Quot.data[7] = data[7] * tmp;
435 Quot.data[2] = data[2] * tmp;
436 Quot.data[5] = data[5] * tmp;
437 Quot.data[8] = data[8] * tmp;
446 double tmp = 1.0/scalar;
487 double tmp1 = v1*data[0];
488 double tmp2 = v1*data[1];
489 double tmp3 = v1*data[2];
This class implements a 3 element column vector.
Handles matrix math operations.
void T(void)
Transposes this matrix.
FGMatrix33 operator+(const FGMatrix33 &B) const
Matrix addition.
FGMatrix33 & operator+=(const FGMatrix33 &B)
In place matrix addition.
unsigned int Cols(void) const
Number of cloumns in the matrix.
FGMatrix33 & operator*=(const FGMatrix33 &B)
In place matrix multiplication.
FGColumnVector3 operator*(const FGColumnVector3 &v) const
Matrix vector multiplication.
FGMatrix33 Inverse(void) const
Return the inverse of the matrix.
double Determinant(void) const
Determinant of the matrix.
FGMatrix33 & operator/=(const double scalar)
In place matrix scale.
FGMatrix33 operator-(const FGMatrix33 &B) const
Matrix subtraction.
std::string Dump(const std::string &delimeter) const
Prints the contents of the matrix.
FGQuaternion GetQuaternion(void) const
Returns the quaternion associated with this direction cosine (rotation) matrix.
FGMatrix33 & operator-=(const FGMatrix33 &B)
In place matrix subtraction.
unsigned int Rows(void) const
Number of rows in the matrix.
FGMatrix33 operator/(const double scalar) const
Multiply the matrix with 1.0/scalar.
FGMatrix33(void)
Default initializer.
void InitMatrix(void)
Initialize the matrix.
FGColumnVector3 GetEuler() const
Returns the Euler angle column vector associated with this matrix.
Models the Quaternion representation of rotations.