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 "FGColumnVector3.h"
22 #include "FGMatrix33.h"
25 static const char *IdSrc = "$Id$";
26 static const char *IdHdr = ID_COLUMNVECTOR3;
28 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
32 FGColumnVector3::FGColumnVector3(void)
36 //cout << "Allocated: " << data << endl;
37 //if (debug_lvl & 2) cout << "Instantiated: FGColumnVector3" << endl;
40 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 FGColumnVector3::FGColumnVector3(int m)
46 data[1]=0;data[2]=0;data[3]=0;
47 //cout << "Allocated: " << data << endl;
48 //if (debug_lvl & 2) cout << "Instantiated: FGColumnVector3" << endl;
51 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 FGColumnVector3::~FGColumnVector3(void)
55 //cout << "Freed: " << data << endl;
58 if (debug_lvl & 2) cout << "Destroyed: FGColumnVector3" << endl;
62 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 FGColumnVector3::FGColumnVector3(const FGColumnVector3& b)
72 if (debug_lvl & 2) cout << "Instantiated: FGColumnVector3" << endl;
75 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 FGColumnVector3 FGColumnVector3::operator=(const FGColumnVector3& b)
85 if (debug_lvl & 2) cout << "Instantiated: FGColumnVector3" << endl;
91 /* //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93 double& FGColumnVector3::operator()(int m) const
99 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101 /* FGColumnVector3 operator*(const FGMatrix33& Mat, FGColumnVector3& Col)
103 FGColumnVector3 Product;
105 Product(1) = Col(1)*Mat(1,1) + Col(2)*Mat(1,2) + Col(3)*Mat(1,3);
106 Product(2) = Col(1)*Mat(2,1) + Col(2)*Mat(2,2) + Col(3)*Mat(2,3);
107 Product(3) = Col(1)*Mat(3,1) + Col(2)*Mat(3,2) + Col(3)*Mat(3,3);
113 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115 FGColumnVector3 FGColumnVector3::operator+(const FGColumnVector3& C)
118 Sum(1) = C(1) + data[1];
119 Sum(2) = C(2) + data[2];
120 Sum(3) = C(3) + data[3];
125 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
127 void FGColumnVector3::operator+=(const FGColumnVector3& C)
134 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136 FGColumnVector3 FGColumnVector3::operator*(const double scalar)
138 FGColumnVector3 Product;
140 Product(1) = scalar * data[1];
141 Product(2) = scalar * data[2];
142 Product(3) = scalar * data[3];
147 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
149 void FGColumnVector3::operator*=(const double scalar)
156 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
158 FGColumnVector3 FGColumnVector3::operator-(const FGColumnVector3& V)
161 FGColumnVector3 Diff;
163 Diff(1) = data[1] - V(1);
164 Diff(2) = data[2] - V(2);
165 Diff(3) = data[3] - V(3);
170 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
172 void FGColumnVector3::operator-=(const FGColumnVector3& V)
179 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181 FGColumnVector3 FGColumnVector3::operator/(const double scalar)
183 FGColumnVector3 Quotient;
186 double tmp = 1.0/scalar;
187 Quotient(1) = data[1] * tmp;
188 Quotient(2) = data[2] * tmp;
189 Quotient(3) = data[3] * tmp;
191 cerr << "Attempt to divide by zero in method FGColumnVector3::operator/(const double scalar), object " << this << endl;
196 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
198 void FGColumnVector3::operator/=(const double scalar)
200 FGColumnVector3 Quotient;
203 double tmp = 1.0/scalar;
208 cerr << "Attempt to divide by zero in method FGColumnVector3::operator/=(const double scalar), object " << this << endl;
212 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
214 FGColumnVector3 operator*(const double scalar, const FGColumnVector3& C)
216 FGColumnVector3 Product;
218 Product(1) = scalar * C(1);
219 Product(2) = scalar * C(2);
220 Product(3) = scalar * C(3);
225 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
227 float FGColumnVector3::Magnitude(void)
231 if ((data[1] == 0.00) &&
237 num = data[1]*data[1];
238 num += data[2]*data[2];
239 num += data[3]*data[3];
244 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
246 FGColumnVector3 FGColumnVector3::Normalize(void)
248 double Mag = Magnitude();
260 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
262 FGColumnVector3 FGColumnVector3::operator*(const FGColumnVector3& V)
264 FGColumnVector3 Product;
266 Product(1) = data[2] * V(3) - data[3] * V(2);
267 Product(2) = data[3] * V(1) - data[1] * V(3);
268 Product(3) = data[1] * V(2) - data[2] * V(1);
273 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
275 void FGColumnVector3::operator*=(const FGColumnVector3& V)
278 a = data[1]; b=data[2]; c=data[3];
280 data[1] = b * V(3) - c * V(2);
281 data[2] = c * V(1) - a * V(3);
282 data[3] = a * V(2) - b * V(1);
286 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
288 FGColumnVector3 FGColumnVector3::multElementWise(const FGColumnVector3& V)
290 FGColumnVector3 Product;
292 Product(1) = data[1] * V(1);
293 Product(2) = data[2] * V(2);
294 Product(3) = data[3] * V(3);
299 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
301 void FGColumnVector3::Debug(void)
303 //TODO: Add your source code here
306 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
308 ostream& operator<<(ostream& os, const FGColumnVector3& col)
310 os << col(1) << " , " << col(2) << " , " << col(3);
314 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
316 FGColumnVector3& FGColumnVector3::operator<<(const float ff)