JSBSim Flight Dynamics Model 1.3.0 (09 Apr 2026)
An Open Source Flight Dynamics and Control Software Library in C++
Loading...
Searching...
No Matches
FGColumnVector3.cpp
1/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3Module: FGColumnVector3.cpp
4Author: Originally by Tony Peden [formatted here by JSB]
5Date started: 1998
6Purpose: FGColumnVector3 class
7Called by: Various
8
9 ------------- Copyright (C) 1998 Tony Peden and Jon S. Berndt (jon@jsbsim.org) -
10
11 This program is free software; you can redistribute it and/or modify it under
12 the terms of the GNU Lesser General Public License as published by the Free Software
13 Foundation; either version 2 of the License, or (at your option) any later
14 version.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
19 details.
20
21 You should have received a copy of the GNU Lesser General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23 Place - Suite 330, Boston, MA 02111-1307, USA.
24
25 Further information about the GNU Lesser General Public License can also be found on
26 the world wide web at http://www.gnu.org.
27
28FUNCTIONAL DESCRIPTION
29--------------------------------------------------------------------------------
30
31HISTORY
32--------------------------------------------------------------------------------
33??/??/?? TP Created
3403/16/2000 JSB Added exception throwing
35
36%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37INCLUDES
38%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
39
40#include <iostream>
41#include <sstream>
42#include <iomanip>
43#include <cmath>
44
45#include "FGJSBBase.h"
46#include "FGColumnVector3.h"
47#include "input_output/FGLog.h"
48
49using namespace std;
50
51namespace JSBSim {
52
53/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54CLASS IMPLEMENTATION
55%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
56
58{
59 data[0] = data[1] = data[2] = 0.0;
60 // Debug(0);
61}
62
63//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64
65string FGColumnVector3::Dump(const string& delimiter) const
66{
67 ostringstream buffer;
68 buffer << std::setprecision(16) << data[0] << delimiter;
69 buffer << std::setprecision(16) << data[1] << delimiter;
70 buffer << std::setprecision(16) << data[2];
71 return buffer.str();
72}
73
74//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75
76ostream& operator<<(ostream& os, const FGColumnVector3& col)
77{
78 os << col(1) << " , " << col(2) << " , " << col(3);
79 return os;
80}
81
82//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83
85{
86 if (scalar != 0.0)
87 return operator*( 1.0/scalar );
88
89 FGLogging log(LogLevel::ERROR);
90 log << "Attempt to divide by zero in method \
91 FGColumnVector3::operator/(const double scalar), \
92 object " << data[0] << " , " << data[1] << " , " << data[2] << "\n";
93 return FGColumnVector3();
94}
95
96//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97
99{
100 if (scalar != 0.0)
101 operator*=( 1.0/scalar );
102 else {
103 FGLogging log(LogLevel::ERROR);
104 log << "Attempt to divide by zero in method \
105 FGColumnVector3::operator/=(const double scalar), \
106 object " << data[0] << " , " << data[1] << " , " << data[2] << "\n";
107 }
108
109 return *this;
110}
111
112//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113
115{
116 return sqrt( data[0]*data[0] + data[1]*data[1] + data[2]*data[2] );
117}
118
119//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120
122{
123 double Mag = Magnitude();
124
125 if (Mag != 0.0)
126 operator*=( 1.0/Mag );
127
128 return *this;
129}
130
131//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
132
133double FGColumnVector3::Magnitude(const int idx1, const int idx2) const {
134 return sqrt( data[idx1-1]*data[idx1-1] + data[idx2-1]*data[idx2-1] );
135}
136
137
138} // namespace JSBSim
This class implements a 3 element column vector.
FGColumnVector3 operator*(const double scalar) const
Multiplication by a scalar.
FGColumnVector3 & operator/=(const double scalar)
Scale by a 1/scalar.
FGColumnVector3 & operator*=(const double scalar)
Scale by a scalar.
double Magnitude(void) const
Length of the vector.
FGColumnVector3 operator/(const double scalar) const
Multiply by 1/scalar.
std::string Dump(const std::string &delimeter) const
Prints the contents of the vector.
FGColumnVector3(void)
Default initializer.
FGColumnVector3 & Normalize(void)
Normalize.
Main namespace for the JSBSim Flight Dynamics Model.
Definition FGFDMExec.cpp:71
ostream & operator<<(ostream &os, const FGColumnVector3 &col)
Write vector to a stream.