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)
34 //cout << "Allocated: " << data << endl;
35 if (debug_lvl & 2) cout << "Instantiated: FGColumnVector4" << endl;
38 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40 FGColumnVector4::FGColumnVector4(int m)
44 data[1]=0;data[2]=0;data[3]=0;data[4]=0;
45 //cout << "Allocated: " << data << endl;
46 if (debug_lvl & 2) cout << "Instantiated: FGColumnVector4" << endl;
49 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 FGColumnVector4::~FGColumnVector4(void)
53 //cout << "Freed: " << data << endl;
56 if (debug_lvl & 2) cout << "Destroyed: FGColumnVector4" << endl;
60 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62 FGColumnVector4::FGColumnVector4(const FGColumnVector4& b)
72 if (debug_lvl & 2) cout << "Instantiated: FGColumnVector4" << endl;
75 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 FGColumnVector4 FGColumnVector4::operator=(const FGColumnVector4& b)
86 if (debug_lvl & 2) cout << "Instantiated: FGColumnVector4" << endl;
91 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93 FGColumnVector4 FGColumnVector4::operator+(const FGColumnVector4& C)
97 Sum(1) = C(1) + data[1];
98 Sum(2) = C(2) + data[2];
99 Sum(3) = C(3) + data[3];
100 Sum(4) = C(4) + data[4];
104 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106 void FGColumnVector4::operator+=(const FGColumnVector4& C)
114 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116 FGColumnVector4 FGColumnVector4::operator*(const double scalar)
118 FGColumnVector4 Product;
120 Product(1) = scalar * data[1];
121 Product(2) = scalar * data[2];
122 Product(3) = scalar * data[3];
123 Product(4) = scalar * data[4];
128 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130 void FGColumnVector4::operator*=(const double scalar)
138 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
140 FGColumnVector4 FGColumnVector4::operator-(const FGColumnVector4& V)
143 FGColumnVector4 Diff;
145 Diff(1) = data[1] - V(1);
146 Diff(2) = data[2] - V(2);
147 Diff(3) = data[3] - V(3);
148 Diff(4) = data[4] - V(4);
153 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
155 void FGColumnVector4::operator-=(const FGColumnVector4& V)
163 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
165 FGColumnVector4 FGColumnVector4::operator/(const double scalar)
167 FGColumnVector4 Quotient;
170 double tmp = 1.0/scalar;
171 Quotient(1) = data[1] * tmp;
172 Quotient(2) = data[2] * tmp;
173 Quotient(3) = data[3] * tmp;
174 Quotient(4) = data[4] * tmp;
176 cerr << "Attempt to divide by zero in method FGColumnVector4::operator/(const double scalar), object " << this << endl;
181 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
183 void FGColumnVector4::operator/=(const double scalar)
185 FGColumnVector4 Quotient;
188 double tmp = 1.0/scalar;
194 cerr << "Attempt to divide by zero in method FGColumnVector4::operator/=(const double scalar), object " << this << endl;
198 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
200 FGColumnVector4 operator*(const double scalar, const FGColumnVector4& C)
202 FGColumnVector4 Product;
204 Product(1) = scalar * C(1);
205 Product(2) = scalar * C(2);
206 Product(3) = scalar * C(3);
207 Product(4) = scalar * C(4);
211 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
213 float FGColumnVector4::Magnitude(void)
217 if ((data[1] == 0.00) &&
224 num = data[1]*data[1];
225 num += data[2]*data[2];
226 num += data[3]*data[3];
227 num += data[4]*data[4];
232 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
234 FGColumnVector4 FGColumnVector4::Normalize(void)
236 double Mag = Magnitude();
249 /* //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
251 FGColumnVector4 FGColumnVector4::operator*(const FGColumnVector4& V)
253 FGColumnVector4 Product;
255 Product(1) = data[2] * V(3) - data[3] * V(2);
256 Product(2) = data[3] * V(1) - data[1] * V(3);
257 Product(3) = data[1] * V(2) - data[2] * V(1);
263 /* //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
265 void FGColumnVector4::operator*=(const FGColumnVector4& V)
268 a = data[1]; b=data[2]; c=data[3];
270 data[1] = b * V(3) - c * V(2);
271 data[2] = c * V(1) - a * V(3);
272 data[3] = a * V(2) - b * V(1);
277 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
279 FGColumnVector4 FGColumnVector4::multElementWise(const FGColumnVector4& V)
281 FGColumnVector4 Product;
283 Product(1) = data[1] * V(1);
284 Product(2) = data[2] * V(2);
285 Product(3) = data[3] * V(3);
286 Product(4) = data[4] * V(4);
291 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
293 void FGColumnVector4::Debug(void)
295 //TODO: Add your source code here
298 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
300 ostream& operator<<(ostream& os, FGColumnVector4& col)
302 os << col(1) << " , " << col(2) << " , " << col(3) << " , " << col(4);
306 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
308 FGColumnVector4& FGColumnVector4::operator<<(const float ff)