JSBSim Flight Dynamics Model 1.2.2 (22 Mar 2025)
An Open Source Flight Dynamics and Control Software Library in C++
Loading...
Searching...
No Matches
FGColumnVector3.h
1/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3Header: FGColumnVector3.h
4Author: Originally by Tony Peden [formatted and adapted here by Jon Berndt]
5Date 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
11 Software Foundation; either version 2 of the License, or (at your option) any
12 later 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
20 with this program; if not, write to the Free Software Foundation, Inc., 59
21 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23 Further information about the GNU Lesser General Public License can also be
24 found on the world wide web at http://www.gnu.org.
25
26HISTORY
27--------------------------------------------------------------------------------
28??/??/???? ?? Initial version and more.
2903/06/2004 MF Rework, document and do much inlineing.
30
31%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32SENTRY
33%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
34
35#ifndef FGCOLUMNVECTOR3_H
36#define FGCOLUMNVECTOR3_H
37
38/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39INCLUDES
40%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
41
42#include <iosfwd>
43#include <string>
44
45#include "JSBSim_API.h"
46
47/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48FORWARD DECLARATIONS
49%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
50
51namespace JSBSim {
52
53/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54CLASS DOCUMENTATION
55%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
56
61/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62CLASS DECLARATION
63%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
64
65class JSBSIM_API FGColumnVector3
66{
67public:
70 FGColumnVector3(void);
71
77 FGColumnVector3(const double X, const double Y, const double Z) {
78 data[0] = X;
79 data[1] = Y;
80 data[2] = Z;
81 }
82
87 data[0] = v.data[0];
88 data[1] = v.data[1];
89 data[2] = v.data[2];
90 }
91
94
100 double operator()(const unsigned int idx) const { return data[idx-1]; }
101
107 double& operator()(const unsigned int idx) { return data[idx-1]; }
108
117 double Entry(const unsigned int idx) const { return data[idx-1]; }
118
127 double& Entry(const unsigned int idx) { return data[idx-1]; }
128
132 std::string Dump(const std::string& delimeter) const;
133
138 data[0] = b.data[0];
139 data[1] = b.data[1];
140 data[2] = b.data[2];
141 return *this;
142 }
143
147 FGColumnVector3& operator=(std::initializer_list<double> lv) {
148 double *v = data;
149 for(auto &x : lv)
150 *(v++) = x;
151
152 return *this;
153 }
154
158 bool operator==(const FGColumnVector3& b) const {
159 return data[0] == b.data[0] && data[1] == b.data[1] && data[2] == b.data[2];
160 }
161
165 bool operator!=(const FGColumnVector3& b) const { return ! operator==(b); }
166
171 FGColumnVector3 operator*(const double scalar) const {
172 return FGColumnVector3(scalar*data[0], scalar*data[1], scalar*data[2]);
173 }
174
179 FGColumnVector3 operator/(const double scalar) const;
180
187 return FGColumnVector3( data[1] * V.data[2] - data[2] * V.data[1],
188 data[2] * V.data[0] - data[0] * V.data[2],
189 data[0] * V.data[1] - data[1] * V.data[0] );
190 }
191
194 return FGColumnVector3( data[0] + B.data[0], data[1] + B.data[1],
195 data[2] + B.data[2] );
196 }
197
200 return FGColumnVector3( data[0] - B.data[0], data[1] - B.data[1],
201 data[2] - B.data[2] );
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
214 data[0] += B.data[0];
215 data[1] += B.data[1];
216 data[2] += B.data[2];
217 return *this;
218 }
219
221 FGColumnVector3& operator*=(const double scalar) {
222 data[0] *= scalar;
223 data[1] *= scalar;
224 data[2] *= scalar;
225 return *this;
226 }
227
229 FGColumnVector3& operator/=(const double scalar);
230
231 void InitMatrix(void) { data[0] = data[1] = data[2] = 0.0; }
232 void InitMatrix(const double a) { data[0] = data[1] = data[2] = a; }
233 void InitMatrix(const double a, const double b, const double c) {
234 data[0]=a; data[1]=b; data[2]=c;
235 }
236
239 double Magnitude(void) const;
240
244 double Magnitude(const int idx1, const int idx2) const;
245
249 FGColumnVector3& Normalize(void);
250
251private:
252 double data[3];
253};
254
258inline double DotProduct(const FGColumnVector3& v1, const FGColumnVector3& v2) {
259 return v1(1)*v2(1) + v1(2)*v2(2) + v1(3)*v2(3);
260}
261
267inline FGColumnVector3 operator*(double scalar, const FGColumnVector3& A) {
268 // use already defined operation.
269 return A*scalar;
270}
271
276JSBSIM_API std::ostream& operator<<(std::ostream& os, const FGColumnVector3& col);
277
278} // namespace JSBSim
279
280//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
281#endif
This class implements a 3 element column vector.
FGColumnVector3 operator*(const double scalar) const
Multiplication by a scalar.
FGColumnVector3 operator+(const FGColumnVector3 &B) const
Addition operator.
FGColumnVector3 operator-(const FGColumnVector3 &B) const
Subtraction operator.
FGColumnVector3 & operator*=(const double scalar)
Scale by a scalar.
FGColumnVector3 & operator+=(const FGColumnVector3 &B)
Add an other vector.
bool operator==(const FGColumnVector3 &b) const
Comparison operator.
FGColumnVector3 operator*(const FGColumnVector3 &V) const
Cross product multiplication.
double & operator()(const unsigned int idx)
Write access the entries of the vector.
FGColumnVector3 & operator=(const FGColumnVector3 &b)
Assignment operator.
FGColumnVector3 & operator-=(const FGColumnVector3 &B)
Subtract an other vector.
double & Entry(const unsigned int idx)
Write access the entries of the vector.
FGColumnVector3 & operator=(std::initializer_list< double > lv)
Assignment operator.
bool operator!=(const FGColumnVector3 &b) const
Comparison operator.
double Entry(const unsigned int idx) const
Read access the entries of the vector.
FGColumnVector3(const FGColumnVector3 &v)
Copy constructor.
~FGColumnVector3(void)
Destructor.
FGColumnVector3(const double X, const double Y, const double Z)
Initialization by given values.
double operator()(const unsigned int idx) const
Read access the entries of the vector.