44
#include "FGJSBBase.h"
46
45
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48
47
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
50
#define ID_COLUMNVECTOR3 "$Id$"
49
#define ID_COLUMNVECTOR3 "$Id: FGColumnVector3.h,v 1.16 2010/12/07 12:57:14 jberndt Exp $"
52
51
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53
52
FORWARD DECLARATIONS
62
61
/** This class implements a 3 element column vector.
63
62
@author Jon S. Berndt, Tony Peden, et. al.
63
@version $Id: FGColumnVector3.h,v 1.16 2010/12/07 12:57:14 jberndt Exp $
67
66
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69
68
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
71
class FGColumnVector3 : public FGJSBBase
74
73
/** Default initializer.
80
79
@param Y value of the y-conponent.
81
80
@param Z value of the z-conponent.
82
81
Create a vector from the doubles given in the arguments. */
83
FGColumnVector3(double X, double Y, double Z) {
82
FGColumnVector3(const double X, const double Y, const double Z) {
90
88
/** Copy constructor.
94
92
data[0] = v.data[0];
95
93
data[1] = v.data[1];
96
94
data[2] = v.data[2];
101
~FGColumnVector3(void) { Debug(1); }
98
~FGColumnVector3(void) { }
103
100
/** Read access the entries of the vector.
104
101
@param idx the component index.
105
102
Return the value of the matrix entry at the given index.
106
103
Indices are counted starting with 1.
107
104
Note that the index given in the argument is unchecked. */
108
double operator()(unsigned int idx) const { return Entry(idx); }
105
double operator()(const unsigned int idx) const { return data[idx-1]; }
110
107
/** Write access the entries of the vector.
111
108
@param idx the component index.
112
109
Return a reference to the vector entry at the given index.
113
110
Indices are counted starting with 1.
114
111
Note that the index given in the argument is unchecked. */
115
double& operator()(unsigned int idx) { return Entry(idx); }
112
double& operator()(const unsigned int idx) { return data[idx-1]; }
117
114
/** Read access the entries of the vector.
118
115
@param idx the component index.
122
119
operator()(unsigned int idx) const</tt> function. It is
123
120
used internally to access the elements in a more convenient way.
124
121
Note that the index given in the argument is unchecked. */
125
double Entry(unsigned int idx) const { return data[idx-1]; }
122
double Entry(const unsigned int idx) const { return data[idx-1]; }
127
124
/** Write access the entries of the vector.
128
125
@param idx the component index.
132
129
operator()(unsigned int idx)</tt> function. It is
133
130
used internally to access the elements in a more convenient way.
134
131
Note that the index given in the argument is unchecked. */
135
double& Entry(unsigned int idx) { return data[idx-1]; }
132
double& Entry(const unsigned int idx) { return data[idx-1]; }
137
134
/** Prints the contents of the vector
138
135
@param delimeter the item separator (tab or comma)
166
163
@return The resulting vector from the multiplication with that scalar.
167
164
Multiply the vector with the scalar given in the argument. */
168
165
FGColumnVector3 operator*(const double scalar) const {
169
return FGColumnVector3(scalar*Entry(1), scalar*Entry(2), scalar*Entry(3));
166
return FGColumnVector3(scalar*data[0], scalar*data[1], scalar*data[2]);
172
169
/** Multiply by 1/scalar.
181
178
Compute and return the cross product of the current vector with
182
179
the given argument. */
183
180
FGColumnVector3 operator*(const FGColumnVector3& V) const {
184
return FGColumnVector3( Entry(2) * V(3) - Entry(3) * V(2),
185
Entry(3) * V(1) - Entry(1) * V(3),
186
Entry(1) * V(2) - Entry(2) * V(1) );
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] );
189
186
/// Addition operator.
190
187
FGColumnVector3 operator+(const FGColumnVector3& B) const {
191
return FGColumnVector3( Entry(1) + B(1), Entry(2) + B(2), Entry(3) + B(3) );
188
return FGColumnVector3( data[0] + B.data[0], data[1] + B.data[1], data[2] + B.data[2] );
194
191
/// Subtraction operator.
195
192
FGColumnVector3 operator-(const FGColumnVector3& B) const {
196
return FGColumnVector3( Entry(1) - B(1), Entry(2) - B(2), Entry(3) - B(3) );
193
return FGColumnVector3( data[0] - B.data[0], data[1] - B.data[1], data[2] - B.data[2] );
199
196
/// Subtract an other vector.
200
197
FGColumnVector3& operator-=(const FGColumnVector3 &B) {
198
data[0] -= B.data[0];
199
data[1] -= B.data[1];
200
data[2] -= B.data[2];
207
204
/// Add an other vector.
208
205
FGColumnVector3& operator+=(const FGColumnVector3 &B) {
206
data[0] += B.data[0];
207
data[1] += B.data[1];
208
data[2] += B.data[2];
215
212
/// Scale by a scalar.
216
213
FGColumnVector3& operator*=(const double scalar) {
224
221
FGColumnVector3& operator/=(const double scalar);
226
223
void InitMatrix(void) { data[0] = data[1] = data[2] = 0.0; }
227
void InitMatrix(double a) { data[0] = data[1] = data[2] = a; }
228
void InitMatrix(double a, double b, double c) {
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) {
229
226
data[0]=a; data[1]=b; data[2]=c;
236
233
/** Length of the vector in a coordinate axis plane.
237
234
Compute and return the euclidean norm of this vector projected into
238
235
the coordinate axis plane idx1-idx2. */
239
double Magnitude(int idx1, int idx2) const {
240
return sqrt( Entry(idx1)*Entry(idx1) + Entry(idx2)*Entry(idx2) );
236
double Magnitude(const int idx1, const int idx2) const;
244
239
Normalize the vector to have the Magnitude() == 1.0. If the vector
245
240
is equal to zero it is left untouched. */
246
241
FGColumnVector3& Normalize(void);
248
// little trick here.
250
AssignRef(FGColumnVector3& r, int i) : Ref(r), idx(i) {}
251
AssignRef operator<<(const double ff) {
253
return AssignRef(Ref, idx+1);
255
FGColumnVector3& Ref;
258
AssignRef operator<<(const double ff) {
260
return AssignRef(*this, 2);
243
/** Dot product of two vectors
244
Compute and return the euclidean dot (or scalar) product of two vectors
246
friend inline double DotProduct(const FGColumnVector3& v1, const FGColumnVector3& v2) {
247
return v1.data[0]*v2.data[0] + v1.data[1]*v2.data[1] + v1.data[2]*v2.data[2];
266
void Debug(int from);
269
254
/** Scalar multiplication.
270
255
@param scalar scalar value to multiply with.
271
256
@param A Vector to multiply.
272
Multiply the Vector with a scalar value.*/
257
Multiply the Vector with a scalar value. Note: At this time, this
258
operator MUST be inlined, or a multiple definition link error will occur.*/
273
259
inline FGColumnVector3 operator*(double scalar, const FGColumnVector3& A) {
274
260
// use already defined operation.
278
264
/** Write vector to a stream.
279
265
@param os Stream to write to.
280
@param M Matrix to write.
281
Write the matrix to a stream.*/
266
@param col vector to write.
267
Write the vector to a stream.*/
282
268
std::ostream& operator<<(std::ostream& os, const FGColumnVector3& col);
284
270
} // namespace JSBSim