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 "FGColumnVector4.h"
23 static const char *IdSrc = "$Id$";
24 static const char *IdHdr = ID_COLUMNVECTOR4;
26 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
30 FGColumnVector4::FGColumnVector4(void)
33 data[1]=0;data[2]=0;data[3]=0;data[4]=0;
38 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40 FGColumnVector4::FGColumnVector4(double A, double B, double C, double D)
43 data[1]=0;data[2]=0;data[3]=0;data[4]=0;
48 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 FGColumnVector4::~FGColumnVector4(void)
56 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 FGColumnVector4::FGColumnVector4(const FGColumnVector4& b)
70 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 FGColumnVector4 FGColumnVector4::operator=(const FGColumnVector4& b)
82 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84 FGColumnVector4 FGColumnVector4::operator+(const FGColumnVector4& C)
88 Sum(1) = C(1) + data[1];
89 Sum(2) = C(2) + data[2];
90 Sum(3) = C(3) + data[3];
91 Sum(4) = C(4) + data[4];
95 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97 void FGColumnVector4::operator+=(const FGColumnVector4& C)
105 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 FGColumnVector4 FGColumnVector4::operator*(const double scalar)
109 FGColumnVector4 Product;
111 Product(1) = scalar * data[1];
112 Product(2) = scalar * data[2];
113 Product(3) = scalar * data[3];
114 Product(4) = scalar * data[4];
119 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121 void FGColumnVector4::operator*=(const double scalar)
129 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 FGColumnVector4 FGColumnVector4::operator-(const FGColumnVector4& V)
134 FGColumnVector4 Diff;
136 Diff(1) = data[1] - V(1);
137 Diff(2) = data[2] - V(2);
138 Diff(3) = data[3] - V(3);
139 Diff(4) = data[4] - V(4);
144 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146 void FGColumnVector4::operator-=(const FGColumnVector4& V)
154 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
156 FGColumnVector4 FGColumnVector4::operator/(const double scalar)
158 FGColumnVector4 Quotient;
161 double tmp = 1.0/scalar;
162 Quotient(1) = data[1] * tmp;
163 Quotient(2) = data[2] * tmp;
164 Quotient(3) = data[3] * tmp;
165 Quotient(4) = data[4] * tmp;
167 cerr << "Attempt to divide by zero in method FGColumnVector4::operator/(const double scalar), object " << this << endl;
172 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
174 void FGColumnVector4::operator/=(const double scalar)
176 FGColumnVector4 Quotient;
179 double tmp = 1.0/scalar;
185 cerr << "Attempt to divide by zero in method FGColumnVector4::operator/=(const double scalar), object " << this << endl;
189 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
191 FGColumnVector4 operator*(const double scalar, const FGColumnVector4& C)
193 FGColumnVector4 Product;
195 Product(1) = scalar * C(1);
196 Product(2) = scalar * C(2);
197 Product(3) = scalar * C(3);
198 Product(4) = scalar * C(4);
202 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
204 double FGColumnVector4::Magnitude(void)
208 if ((data[1] == 0.00) &&
215 num = data[1]*data[1];
216 num += data[2]*data[2];
217 num += data[3]*data[3];
218 num += data[4]*data[4];
223 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
225 FGColumnVector4 FGColumnVector4::Normalize(void)
227 double Mag = Magnitude();
240 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
242 FGColumnVector4 FGColumnVector4::multElementWise(const FGColumnVector4& V)
244 FGColumnVector4 Product;
246 Product(1) = data[1] * V(1);
247 Product(2) = data[2] * V(2);
248 Product(3) = data[3] * V(3);
249 Product(4) = data[4] * V(4);
254 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
256 ostream& operator<<(ostream& os, FGColumnVector4& col)
258 os << col(1) << " , " << col(2) << " , " << col(3) << " , " << col(4);
262 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
264 FGColumnVector4& FGColumnVector4::operator<<(const double ff)
267 if (++rowCtr > 4) rowCtr = 1;
270 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
271 // The bitmasked value choices are as follows:
272 // unset: In this case (the default) JSBSim would only print
273 // out the normally expected messages, essentially echoing
274 // the config files as they are read. If the environment
275 // variable is not set, debug_lvl is set to 1 internally
276 // 0: This requests JSBSim not to output any messages
278 // 1: This value explicity requests the normal JSBSim
280 // 2: This value asks for a message to be printed out when
281 // a class is instantiated
282 // 4: When this value is set, a message is displayed when a
283 // FGModel object executes its Run() method
284 // 8: When this value is set, various runtime state variables
285 // are printed out periodically
286 // 16: When set various parameters are sanity checked and
287 // a message is printed out when they go out of bounds
289 void FGColumnVector4::Debug(int from)
291 if (debug_lvl <= 0) return;
293 if (debug_lvl & 1) { // Standard console startup message output
295 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
296 if (from == 0) cout << "Instantiated: FGColumnVector4" << endl;
297 if (from == 1) cout << "Destroyed: FGColumnVector4" << endl;
299 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
301 if (debug_lvl & 8 ) { // Runtime state variables
303 if (debug_lvl & 16) { // Sanity checking
305 if (debug_lvl & 64) { // Sanity checking
306 if (from == 0) { // Constructor
307 cout << IdSrc << endl;
308 cout << IdHdr << endl;