1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 Module: FGColumnVector3.cpp
4 Author: Originally by Tony Peden [formatted here (and broken??) by JSB]
6 Purpose: FGColumnVector3 class
10 --------------------------------------------------------------------------------
13 --------------------------------------------------------------------------------
15 03/16/2000 JSB Added exception throwing
17 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
25 #include "FGColumnVector3.h"
30 static const char *IdSrc = "$Id$";
31 static const char *IdHdr = ID_COLUMNVECTOR3;
33 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
37 FGColumnVector3::FGColumnVector3(void)
39 data[0] = data[1] = data[2] = 0.0;
43 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 string FGColumnVector3::Dump(string delimeter) const
48 sprintf(buffer, "%f%s%f%s%f", Entry(1), delimeter.c_str(), Entry(2), delimeter.c_str(), Entry(3));
49 return string(buffer);
52 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 FGColumnVector3 FGColumnVector3::operator/(const double scalar) const
57 return operator*( 1.0/scalar );
59 cerr << "Attempt to divide by zero in method "
60 "FGColumnVector3::operator/(const double scalar), "
61 "object " << this << endl;
62 return FGColumnVector3();
65 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 FGColumnVector3& FGColumnVector3::operator/=(const double scalar)
70 operator*=( 1.0/scalar );
72 cerr << "Attempt to divide by zero in method "
73 "FGColumnVector3::operator/=(const double scalar), "
74 "object " << this << endl;
79 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 double FGColumnVector3::Magnitude(void) const
83 if (Entry(1) == 0.0 && Entry(2) == 0.0 && Entry(3) == 0.0)
86 return sqrt( Entry(1)*Entry(1) + Entry(2)*Entry(2) + Entry(3)*Entry(3) );
89 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91 FGColumnVector3& FGColumnVector3::Normalize(void)
93 double Mag = Magnitude();
96 operator*=( 1.0/Mag );
101 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103 FGColumnVector3 FGColumnVector3::multElementWise(const FGColumnVector3& V) const
105 return FGColumnVector3(Entry(1) * V(1), Entry(2) * V(2), Entry(3) * V(3));
108 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
110 ostream& operator<<(ostream& os, const FGColumnVector3& col)
112 os << col(1) << " , " << col(2) << " , " << col(3);
116 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
117 // The bitmasked value choices are as follows:
118 // unset: In this case (the default) JSBSim would only print
119 // out the normally expected messages, essentially echoing
120 // the config files as they are read. If the environment
121 // variable is not set, debug_lvl is set to 1 internally
122 // 0: This requests JSBSim not to output any messages
124 // 1: This value explicity requests the normal JSBSim
126 // 2: This value asks for a message to be printed out when
127 // a class is instantiated
128 // 4: When this value is set, a message is displayed when a
129 // FGModel object executes its Run() method
130 // 8: When this value is set, various runtime state variables
131 // are printed out periodically
132 // 16: When set various parameters are sanity checked and
133 // a message is printed out when they go out of bounds
135 void FGColumnVector3::Debug(int from)
137 if (debug_lvl <= 0) return;
139 if (debug_lvl & 1) { // Standard console startup message output
141 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
142 if (from == 0) cout << "Instantiated: FGColumnVector3" << endl;
143 if (from == 1) cout << "Destroyed: FGColumnVector3" << endl;
145 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
147 if (debug_lvl & 8 ) { // Runtime state variables
149 if (debug_lvl & 16) { // Sanity checking
151 if (debug_lvl & 64) {
152 if (from == 0) { // Constructor
153 cout << IdSrc << endl;
154 cout << IdHdr << endl;
159 } // namespace JSBSim