JSBSim Flight Dynamics Model  1.0 (02 March 2017)
An Open Source Flight Dynamics and Control Software Library in C++
FGColumnVector3.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 
3 Header: FGColumnVector3.h
4 Author: Originally by Tony Peden [formatted and adapted here by Jon Berndt]
5 Date started: Unknown
6 
7  ------------- Copyright (C) 2001 by Tony Peden and Jon S. Berndt (jon@jsbsim.org)
8 
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13 
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
17  details.
18 
19  You should have received a copy of the GNU Lesser General Public License along with
20  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21  Place - Suite 330, Boston, MA 02111-1307, USA.
22 
23  Further information about the GNU Lesser General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25 
26 HISTORY
27 --------------------------------------------------------------------------------
28 ??/??/???? ?? Initial version and more.
29 03/06/2004 MF Rework, document and do much inlineing.
30 
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32 SENTRY
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
34 
35 #ifndef FGCOLUMNVECTOR3_H
36 #define FGCOLUMNVECTOR3_H
37 
38 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 INCLUDES
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
41 
42 #include <iosfwd>
43 #include <string>
44 
45 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46 DEFINITIONS
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
48 
49 #define ID_COLUMNVECTOR3 "$Id: FGColumnVector3.h,v 1.18 2013/11/30 10:25:33 bcoconni Exp $"
50 
51 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 FORWARD DECLARATIONS
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
54 
55 namespace JSBSim {
56 
57 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 CLASS DOCUMENTATION
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
60 
66 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 CLASS DECLARATION
68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
69 
71 {
72 public:
75  FGColumnVector3(void);
76 
82  FGColumnVector3(const double X, const double Y, const double Z) {
83  data[0] = X;
84  data[1] = Y;
85  data[2] = Z;
86  }
87 
92  data[0] = v.data[0];
93  data[1] = v.data[1];
94  data[2] = v.data[2];
95  }
96 
98  ~FGColumnVector3(void) { }
99 
105  double operator()(const unsigned int idx) const { return data[idx-1]; }
106 
112  double& operator()(const unsigned int idx) { return data[idx-1]; }
113 
122  double Entry(const unsigned int idx) const { return data[idx-1]; }
123 
132  double& Entry(const unsigned int idx) { return data[idx-1]; }
133 
137  std::string Dump(const std::string& delimeter) const;
138 
143  data[0] = b.data[0];
144  data[1] = b.data[1];
145  data[2] = b.data[2];
146  return *this;
147  }
148 
152  bool operator==(const FGColumnVector3& b) const {
153  return data[0] == b.data[0] && data[1] == b.data[1] && data[2] == b.data[2];
154  }
155 
159  bool operator!=(const FGColumnVector3& b) const { return ! operator==(b); }
160 
165  FGColumnVector3 operator*(const double scalar) const {
166  return FGColumnVector3(scalar*data[0], scalar*data[1], scalar*data[2]);
167  }
168 
173  FGColumnVector3 operator/(const double scalar) const;
174 
181  return FGColumnVector3( data[1] * V.data[2] - data[2] * V.data[1],
182  data[2] * V.data[0] - data[0] * V.data[2],
183  data[0] * V.data[1] - data[1] * V.data[0] );
184  }
185 
188  return FGColumnVector3( data[0] + B.data[0], data[1] + B.data[1], data[2] + B.data[2] );
189  }
190 
193  return FGColumnVector3( data[0] - B.data[0], data[1] - B.data[1], data[2] - B.data[2] );
194  }
195 
198  data[0] -= B.data[0];
199  data[1] -= B.data[1];
200  data[2] -= B.data[2];
201  return *this;
202  }
203 
206  data[0] += B.data[0];
207  data[1] += B.data[1];
208  data[2] += B.data[2];
209  return *this;
210  }
211 
213  FGColumnVector3& operator*=(const double scalar) {
214  data[0] *= scalar;
215  data[1] *= scalar;
216  data[2] *= scalar;
217  return *this;
218  }
219 
221  FGColumnVector3& operator/=(const double scalar);
222 
223  void InitMatrix(void) { data[0] = data[1] = data[2] = 0.0; }
224  void InitMatrix(const double a) { data[0] = data[1] = data[2] = a; }
225  void InitMatrix(const double a, const double b, const double c) {
226  data[0]=a; data[1]=b; data[2]=c;
227  }
228 
231  double Magnitude(void) const;
232 
236  double Magnitude(const int idx1, const int idx2) const;
237 
241  FGColumnVector3& Normalize(void);
242 
243 private:
244  double data[3];
245 };
246 
250 inline double DotProduct(const FGColumnVector3& v1, const FGColumnVector3& v2) {
251  return v1(1)*v2(1) + v1(2)*v2(2) + v1(3)*v2(3);
252 }
253 
259 inline FGColumnVector3 operator*(double scalar, const FGColumnVector3& A) {
260  // use already defined operation.
261  return A*scalar;
262 }
263 
268 std::ostream& operator<<(std::ostream& os, const FGColumnVector3& col);
269 
270 } // namespace JSBSim
271 
272 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
273 #endif
FGColumnVector3 & operator=(const FGColumnVector3 &b)
Assignment operator.
FGColumnVector3(const FGColumnVector3 &v)
Copy constructor.
double operator()(const unsigned int idx) const
Read access the entries of the vector.
FGColumnVector3(const double X, const double Y, const double Z)
Initialization by given values.
FGColumnVector3 & operator+=(const FGColumnVector3 &B)
Add an other vector.
FGColumnVector3 & Normalize(void)
Normalize.
bool operator==(const FGColumnVector3 &b) const
Comparison operator.
FGColumnVector3 operator/(const double scalar) const
Multiply by 1/scalar.
double & Entry(const unsigned int idx)
Write access the entries of the vector.
FGColumnVector3 operator*(const FGColumnVector3 &V) const
Cross product multiplication.
FGColumnVector3 operator-(const FGColumnVector3 &B) const
Subtraction operator.
FGColumnVector3 operator*(const double scalar) const
Multiplication by a scalar.
FGColumnVector3 & operator/=(const double scalar)
Scale by a 1/scalar.
std::string Dump(const std::string &delimeter) const
Prints the contents of the vector.
FGColumnVector3 & operator*=(const double scalar)
Scale by a scalar.
double & operator()(const unsigned int idx)
Write access the entries of the vector.
double Entry(const unsigned int idx) const
Read access the entries of the vector.
FGColumnVector3 operator+(const FGColumnVector3 &B) const
Addition operator.
This class implements a 3 element column vector.
~FGColumnVector3(void)
Destructor.
double Magnitude(void) const
Length of the vector.
FGColumnVector3 & operator-=(const FGColumnVector3 &B)
Subtract an other vector.
bool operator!=(const FGColumnVector3 &b) const
Comparison operator.
FGColumnVector3(void)
Default initializer.