]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGColumnVector3.cpp
I forgot a linker dependency. It really si time to figure out why these are all needed.
[flightgear.git] / src / FDM / JSBSim / FGColumnVector3.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3 Module: FGColumnVector3.cpp
4 Author: Originally by Tony Peden [formatted here (and broken??) by JSB]
5 Date started: 1998
6 Purpose: FGColumnVector3 class
7 Called by: Various
8
9 FUNCTIONAL DESCRIPTION
10 --------------------------------------------------------------------------------
11
12 HISTORY
13 --------------------------------------------------------------------------------
14 ??/??/??   TP   Created
15 03/16/2000 JSB  Added exception throwing
16
17 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18 INCLUDES
19 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
20
21 #include "FGColumnVector3.h"
22
23 namespace JSBSim {
24
25 static const char *IdSrc = "$Id$";
26 static const char *IdHdr = ID_COLUMNVECTOR3;
27
28 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29 CLASS IMPLEMENTATION
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
31
32 FGColumnVector3::FGColumnVector3(void)
33 {
34   data[0] = data[1] = data[2] = 0.0;
35   Debug(0);
36 }
37
38 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39
40 FGColumnVector3 FGColumnVector3::operator/(const double scalar) const
41 {
42   if (scalar != 0.0)
43     return operator*( 1.0/scalar );
44
45   cerr << "Attempt to divide by zero in method "
46     "FGColumnVector3::operator/(const double scalar), "
47     "object " << this << endl; 
48   return FGColumnVector3();
49 }
50
51 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52
53 FGColumnVector3& FGColumnVector3::operator/=(const double scalar)
54 {
55   if (scalar != 0.0)
56     operator*=( 1.0/scalar );
57   else
58     cerr << "Attempt to divide by zero in method "
59       "FGColumnVector3::operator/=(const double scalar), "
60       "object " << this << endl;
61
62   return *this;
63 }
64
65 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66
67 double FGColumnVector3::Magnitude(void) const
68 {
69   if (Entry(1) == 0.0 && Entry(2) == 0.0 && Entry(3) == 0.0)
70     return 0.0;
71   else
72     return sqrt( Entry(1)*Entry(1) +  Entry(2)*Entry(2) +  Entry(3)*Entry(3) );
73 }
74
75 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76
77 FGColumnVector3& FGColumnVector3::Normalize(void)
78 {
79   double Mag = Magnitude();
80
81   if (Mag != 0.0)
82     operator*=( 1.0/Mag );
83
84   return *this;
85 }
86
87 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88
89 FGColumnVector3 FGColumnVector3::multElementWise(const FGColumnVector3& V) const
90 {
91   return FGColumnVector3(Entry(1) * V(1), Entry(2) * V(2), Entry(3) * V(3));
92 }
93
94 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95
96 ostream& operator<<(ostream& os, const FGColumnVector3& col)
97 {
98   os << col(1) << " , " << col(2) << " , " << col(3);
99   return os;
100 }  
101
102 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
103 //    The bitmasked value choices are as follows:
104 //    unset: In this case (the default) JSBSim would only print
105 //       out the normally expected messages, essentially echoing
106 //       the config files as they are read. If the environment
107 //       variable is not set, debug_lvl is set to 1 internally
108 //    0: This requests JSBSim not to output any messages
109 //       whatsoever.
110 //    1: This value explicity requests the normal JSBSim
111 //       startup messages
112 //    2: This value asks for a message to be printed out when
113 //       a class is instantiated
114 //    4: When this value is set, a message is displayed when a
115 //       FGModel object executes its Run() method
116 //    8: When this value is set, various runtime state variables
117 //       are printed out periodically
118 //    16: When set various parameters are sanity checked and
119 //       a message is printed out when they go out of bounds
120
121 void FGColumnVector3::Debug(int from)
122 {
123   if (debug_lvl <= 0) return;
124
125   if (debug_lvl & 1) { // Standard console startup message output
126   }
127   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
128     if (from == 0) cout << "Instantiated: FGColumnVector3" << endl;
129     if (from == 1) cout << "Destroyed:    FGColumnVector3" << endl;
130   }
131   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
132   }
133   if (debug_lvl & 8 ) { // Runtime state variables
134   }
135   if (debug_lvl & 16) { // Sanity checking
136   }
137   if (debug_lvl & 64) {
138     if (from == 0) { // Constructor
139       cout << IdSrc << endl;
140       cout << IdHdr << endl;
141     }
142   }
143 }
144
145 } // namespace JSBSim