1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4 Author: Originally by Tony Peden [formatted here (and broken??) by JSB]
6 Purpose: FGMatrix33 class
10 --------------------------------------------------------------------------------
13 --------------------------------------------------------------------------------
15 03/16/2000 JSB Added exception throwing
17 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
21 #include "FGMatrix33.h"
22 #include "FGColumnVector3.h"
24 static const char *IdSrc = "$Id$";
25 static const char *IdHdr = ID_MATRIX33;
27 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
31 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33 FGMatrix33::FGMatrix33(void)
41 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 FGMatrix33::FGMatrix33(int r, int c)
51 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 FGMatrix33::FGMatrix33(const FGMatrix33& M)
57 data[1][1] = M.data[1][1];
58 data[1][2] = M.data[1][2];
59 data[1][3] = M.data[1][3];
60 data[2][1] = M.data[2][1];
61 data[2][2] = M.data[2][2];
62 data[2][3] = M.data[2][3];
63 data[3][1] = M.data[3][1];
64 data[3][2] = M.data[3][2];
65 data[3][3] = M.data[3][3];
70 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 FGMatrix33::~FGMatrix33(void)
79 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 ostream& operator<<(ostream& os, const FGMatrix33& M)
83 for (unsigned int i=1; i<=M.Rows(); i++) {
84 for (unsigned int j=1; j<=M.Cols(); j++) {
85 if (i == M.Rows() && j == M.Cols())
88 os << M.data[i][j] << ", ";
94 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 FGMatrix33& FGMatrix33::operator<<(const double ff)
98 data[rowCtr][colCtr] = ff;
99 if (++colCtr > Cols()) {
101 if (++rowCtr > Rows())
107 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109 istream& operator>>(istream& is, FGMatrix33& M)
111 for (unsigned int i=1; i<=M.Rows(); i++) {
112 for (unsigned int j=1; j<=M.Cols(); j++) {
119 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121 FGMatrix33& FGMatrix33::operator=(const FGMatrix33& M)
124 data[1][1] = M.data[1][1];
125 data[1][2] = M.data[1][2];
126 data[1][3] = M.data[1][3];
127 data[2][1] = M.data[2][1];
128 data[2][2] = M.data[2][2];
129 data[2][3] = M.data[2][3];
130 data[3][1] = M.data[3][1];
131 data[3][2] = M.data[3][2];
132 data[3][3] = M.data[3][3];
137 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139 void FGMatrix33::InitMatrix(double value)
154 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
156 void FGMatrix33::InitMatrix(void)
161 // *****************************************************************************
162 // binary operators ************************************************************
163 // *****************************************************************************
165 FGMatrix33 FGMatrix33::operator-(const FGMatrix33& M)
169 Diff(1,1) = data[1][1] - M(1,1);
170 Diff(1,2) = data[1][2] - M(1,2);
171 Diff(1,3) = data[1][3] - M(1,3);
172 Diff(2,1) = data[2][1] - M(2,1);
173 Diff(2,2) = data[2][2] - M(2,2);
174 Diff(2,3) = data[2][3] - M(2,3);
175 Diff(3,1) = data[3][1] - M(3,1);
176 Diff(3,2) = data[3][2] - M(3,2);
177 Diff(3,3) = data[3][3] - M(3,3);
182 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
184 void FGMatrix33::operator-=(const FGMatrix33 &M)
186 data[1][1] -= M(1,1);
187 data[1][2] -= M(1,2);
188 data[1][3] -= M(1,3);
189 data[2][1] -= M(2,1);
190 data[2][2] -= M(2,2);
191 data[2][3] -= M(2,3);
192 data[3][1] -= M(3,1);
193 data[3][2] -= M(3,2);
194 data[3][3] -= M(3,3);
197 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
199 FGMatrix33 FGMatrix33::operator+(const FGMatrix33& M)
203 Sum(1,1) = data[1][1] + M(1,1);
204 Sum(1,2) = data[1][2] + M(1,2);
205 Sum(1,3) = data[1][3] + M(1,3);
206 Sum(2,1) = data[2][1] + M(2,1);
207 Sum(2,2) = data[2][2] + M(2,2);
208 Sum(2,3) = data[2][3] + M(2,3);
209 Sum(3,1) = data[3][1] + M(3,1);
210 Sum(3,2) = data[3][2] + M(3,2);
211 Sum(3,3) = data[3][3] + M(3,3);
216 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
218 void FGMatrix33::operator+=(const FGMatrix33 &M)
220 data[1][1] += M(1,1);
221 data[1][2] += M(1,2);
222 data[1][3] += M(1,3);
223 data[2][1] += M(2,1);
224 data[2][2] += M(2,2);
225 data[2][3] += M(2,3);
226 data[3][1] += M(3,1);
227 data[3][2] += M(3,2);
228 data[3][3] += M(3,3);
231 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
233 FGMatrix33 FGMatrix33::operator*(const double scalar)
237 Product(1,1) = data[1][1] * scalar;
238 Product(1,2) = data[1][2] * scalar;
239 Product(1,3) = data[1][3] * scalar;
240 Product(2,1) = data[2][1] * scalar;
241 Product(2,2) = data[2][2] * scalar;
242 Product(2,3) = data[2][3] * scalar;
243 Product(3,1) = data[3][1] * scalar;
244 Product(3,2) = data[3][2] * scalar;
245 Product(3,3) = data[3][3] * scalar;
250 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
252 FGMatrix33 operator*(double scalar, FGMatrix33 &M)
256 Product(1,1) = M(1,1) * scalar;
257 Product(1,2) = M(1,2) * scalar;
258 Product(1,3) = M(1,3) * scalar;
259 Product(2,1) = M(2,1) * scalar;
260 Product(2,2) = M(2,2) * scalar;
261 Product(2,3) = M(2,3) * scalar;
262 Product(3,1) = M(3,1) * scalar;
263 Product(3,2) = M(3,2) * scalar;
264 Product(3,3) = M(3,3) * scalar;
269 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
271 void FGMatrix33::operator*=(const double scalar)
273 data[1][1] *= scalar;
274 data[1][2] *= scalar;
275 data[1][3] *= scalar;
276 data[2][1] *= scalar;
277 data[2][2] *= scalar;
278 data[2][3] *= scalar;
279 data[3][1] *= scalar;
280 data[3][2] *= scalar;
281 data[3][3] *= scalar;
284 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
286 FGMatrix33 FGMatrix33::operator*(const FGMatrix33& M)
290 Product(1,1) = data[1][1]*M(1,1) + data[1][2]*M(2,1) + data[1][3]*M(3,1);
291 Product(1,2) = data[1][1]*M(1,2) + data[1][2]*M(2,2) + data[1][3]*M(3,2);
292 Product(1,3) = data[1][1]*M(1,3) + data[1][2]*M(2,3) + data[1][3]*M(3,3);
293 Product(2,1) = data[2][1]*M(1,1) + data[2][2]*M(2,1) + data[2][3]*M(3,1);
294 Product(2,2) = data[2][1]*M(1,2) + data[2][2]*M(2,2) + data[2][3]*M(3,2);
295 Product(2,3) = data[2][1]*M(1,3) + data[2][2]*M(2,3) + data[2][3]*M(3,3);
296 Product(3,1) = data[3][1]*M(1,1) + data[3][2]*M(2,1) + data[3][3]*M(3,1);
297 Product(3,2) = data[3][1]*M(1,2) + data[3][2]*M(2,2) + data[3][3]*M(3,2);
298 Product(3,3) = data[3][1]*M(1,3) + data[3][2]*M(2,3) + data[3][3]*M(3,3);
303 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
305 void FGMatrix33::operator*=(const FGMatrix33& M)
309 a = data[1][1]; b=data[1][2]; c=data[1][3];
310 data[1][1] = a*M(1,1) + b*M(2,1) + c*M(3,1);
311 data[1][2] = a*M(1,2) + b*M(2,2) + c*M(3,2);
312 data[1][3] = a*M(1,3) + b*M(2,3) + c*M(3,3);
314 a = data[2][1]; b=data[2][2]; c=data[2][3];
315 data[2][1] = a*M(1,1) + b*M(2,1) + c*M(3,1);
316 data[2][2] = a*M(1,2) + b*M(2,2) + c*M(3,2);
317 data[2][3] = a*M(1,3) + b*M(2,3) + c*M(3,3);
319 a = data[3][1]; b=data[3][2]; c=data[3][3];
320 data[3][1] = a*M(1,1) + b*M(2,1) + c*M(3,1);
321 data[3][2] = a*M(1,2) + b*M(2,2) + c*M(3,2);
322 data[3][3] = a*M(1,3) + b*M(2,3) + c*M(3,3);
325 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
327 FGMatrix33 FGMatrix33::operator/(const double scalar)
332 double tmp = 1.0/scalar;
333 Quot(1,1) = data[1][1] * tmp;
334 Quot(1,2) = data[1][2] * tmp;
335 Quot(1,3) = data[1][3] * tmp;
336 Quot(2,1) = data[2][1] * tmp;
337 Quot(2,2) = data[2][2] * tmp;
338 Quot(2,3) = data[2][3] * tmp;
339 Quot(3,1) = data[3][1] * tmp;
340 Quot(3,2) = data[3][2] * tmp;
341 Quot(3,3) = data[3][3] * tmp;
344 mE.Message = "Attempt to divide by zero in method FGMatrix33::operator/(const double scalar)";
350 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
352 void FGMatrix33::operator/=(const double scalar)
355 double tmp = 1.0/scalar;
367 mE.Message = "Attempt to divide by zero in method FGMatrix33::operator/=(const double scalar)";
372 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
374 void FGMatrix33::T(void)
376 for (unsigned int i=1; i<=3; i++) {
377 for (unsigned int j=i+1; j<=3; j++) {
378 double tmp = data[i][j];
379 data[i][j] = data[j][i];
385 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
387 FGColumnVector3 FGMatrix33::operator*(const FGColumnVector3& Col)
389 FGColumnVector3 Product;
391 Product(1) = data[1][1]*Col(1) + data[1][2]*Col(2) + data[1][3]*Col(3);
392 Product(2) = data[2][1]*Col(1) + data[2][2]*Col(2) + data[2][3]*Col(3);
393 Product(3) = data[3][1]*Col(1) + data[3][2]*Col(2) + data[3][3]*Col(3);
398 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
399 // The bitmasked value choices are as follows:
400 // unset: In this case (the default) JSBSim would only print
401 // out the normally expected messages, essentially echoing
402 // the config files as they are read. If the environment
403 // variable is not set, debug_lvl is set to 1 internally
404 // 0: This requests JSBSim not to output any messages
406 // 1: This value explicity requests the normal JSBSim
408 // 2: This value asks for a message to be printed out when
409 // a class is instantiated
410 // 4: When this value is set, a message is displayed when a
411 // FGModel object executes its Run() method
412 // 8: When this value is set, various runtime state variables
413 // are printed out periodically
414 // 16: When set various parameters are sanity checked and
415 // a message is printed out when they go out of bounds
417 void FGMatrix33::Debug(int from)
419 if (debug_lvl <= 0) return;
421 if (debug_lvl & 1) { // Standard console startup message output
422 if (from == 0) { // Constructor
426 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
427 if (from == 0) cout << "Instantiated: FGMatrix33" << endl;
428 if (from == 1) cout << "Destroyed: FGMatrix33" << endl;
430 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
432 if (debug_lvl & 8 ) { // Runtime state variables
434 if (debug_lvl & 16) { // Sanity checking
436 if (debug_lvl & 64) {
437 if (from == 0) { // Constructor
438 cout << IdSrc << endl;
439 cout << IdHdr << endl;