VR-Link API Documentation for HLA 1.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vlVector.h
Go to the documentation of this file.
1 /*********************************************************************
2 ** Copyright (c) 1992-2025 MAK Technologies, Inc
3 ** All rights reserved.
4 *********************************************************************/
5 
6 #pragma once
7 
11 
12 #include <vlutil/vlMachineTypes.h>
13 #include <vlutil/vlNetTypes.h>
14 #include <vlutil/vlString.h>
15 #include <matrix/vlMath.h>
16 #include <iomanip>
17 #include <ios>
18 #include <iosfwd>
19 #include <sstream>
20 
21 #ifdef DtUSE_UTILITIES_NAMESPACE
22 namespace DtUSE_UTILITIES_NAMESPACE
23 {
24 #endif
25 
26 
30 {
31  DtX,
32  DtY,
34 };
35 
36 class DtDcm;
37 
48 template <typename T>
49 class DtVectorT
50 {
51 public:
52  inline DtVectorT<T> ();
53 
55  inline DtVectorT<T>( const T& x, const T& y, const T& z);
56 
58  inline ~DtVectorT<T>();
59 
61  inline DtVectorT<T>(const DtVectorT<T>& vec);
62 
64  inline DtVectorT<T>& operator=(const DtVectorT<T>& vec);
65 
67  inline void setToZero();
68 
70  inline void get(T& x, T& y, T& z) const;
74 
76  inline void setAll(const T&x, const T&y, const T&z);
79 
81  inline const T& x() const;
83  inline void setX(const T& x);
85 
87  inline const T& y() const;
89  inline void setY(const T& y);
91 
93  inline const T& z() const;
95  inline void setZ(const T& z);
97 
99  inline T& operator[](int ind);
100 
102  inline T operator[](int ind) const;
103 
105  inline T& operator[](DtVectorOffset ind);
106 
108  inline T operator[](DtVectorOffset ind) const;
109 
112  inline int operator==(const DtVectorT<T>& vec) const;
113 
116  inline int operator!=(const DtVectorT<T>& vec) const;
117 
119  inline DtString string() const;
120 
123  inline double magnitudeSquared() const;
124 
126  inline void normalize();
127 
129  inline bool isNormalized() const;
130 
131 
133  inline bool magnitudeIsZero() const;
134 
138  inline bool magnitudeIsZero(double tolerance) const;
139 
141  inline std::ostream &printDataToStream(std::ostream &str) const;
142 
143 public:
144 
147 
148  inline operator T* ();
149  inline operator const T* () const;
151 
152 protected:
153 
154  T myRep[3];
155 };
156 
157 class DtVector64; //Forward declaration for conversions
158 
159 // Specifically instantiate 32 bit vector.
160 // in C++11 we could just typedef and export, but
161 // this is not compatible with older versions.
162 class DT_DLL_MATRIX DtVector32 : public DtVectorT < float >
163 {
164 public:
165  inline DtVector32();
166 
168  inline DtVector32(const float& x, const float& y, const float& z);
169 
171  inline ~DtVector32();
172 
174  inline DtVector32(const DtVector32& vec);
175  inline DtVector32(const DtVectorT < float >& vec);
176 
178  inline DtVector32& operator=(const DtVector32& vec);
179  inline DtVector32& operator=(const DtVectorT < float >& vec);
180 
182  inline DtVector32 crossProduct(const DtVector32& v) const;
183 
184 #ifdef DtEXPLICIT_VECTOR_CONVERSION
185  inline DtVector32& operator= (const DtVector64& vec);
188  inline DtVector32(const DtVector64& vec);
189 #endif
190 
192  DtVector32 &operator+=(const DtVector32 &other);
193 
195  DtVector32 &operator-=(const DtVector32 &other);
196 
198  float dotProduct(const DtVector32& v) const;
199 
201  bool approxEq(const DtVector32& v, const double& tolerance) const;
202 
203 public:
204 
206  static const DtVector32& zero();
207 
209  static const DtVector32& i();
210 
212  static const DtVector32& j();
213 
215  static const DtVector32& k();
216 
218  static const DtVector32& ones();
219 };
220 
221 // Specifically instantiate 64 bit vector.
222 // in C++11 we could just typedef and export, but
223 // this is not compatible with older versions.
224 class DT_DLL_MATRIX DtVector64 : public DtVectorT < double >
225 {
226 public:
227  inline DtVector64();
228 
230  inline DtVector64(const double& x, const double& y, const double& z);
231 
233  inline ~DtVector64();
234 
236  inline DtVector64(const DtVector64& vec);
237  inline DtVector64(const DtVectorT < double >& vec);
238 
240  inline DtVector64& operator=(const DtVector64& vec);
241  inline DtVector64& operator=(const DtVectorT < double >& vec);
242 
244  inline DtVector64 crossProduct(const DtVector64& v) const;
245 
246 #ifdef DtIMPLICIT_VECTOR_CONVERSION
247  inline DtVector64& operator= (const DtVector32& vec);
250  inline DtVector64(const DtVector32& vec);
251 #endif
252 
254  DtVector64 &operator+=(const DtVector64 &other);
255 
257  DtVector64 &operator-=(const DtVector64 &other);
258 
260  double dotProduct(const DtVector64& v) const;
261 
263  bool approxEq(const DtVector64& v, const double& tolerance) const;
264 
265 
266 public:
267 
269  static const DtVector64& zero();
270 
272  static const DtVector64& i();
273 
275  static const DtVector64& j();
276 
278  static const DtVector64& k();
279 
281  static const DtVector64& ones();
282 };
283 
284 //Helper typedefs
286 typedef const DtVector &DtConstVector;
290 
291 typedef double DtThreeIndex[3][3][3];
292 typedef double (*DtThreeIndexPtr)[3][3];
293 
294 //
295 // Vector routines.
296 //
297 
298 #define DtSetVec(v, x, y, z) v[DtX]=x;v[DtY]=y;v[DtZ]=z;
299 
302 
305 DT_DLL_MATRIX DtVector operator+(const DtVector& v1, const DtVector &v2);
307 DT_DLL_MATRIX DtVector operator+(const DtVector32& v1, const DtVector &v2);
308 DT_DLL_MATRIX DtVector operator+(const DtVector& v1, const DtVector32 &v2);
309 
312 DT_DLL_MATRIX DtVector operator-(const DtVector& v1, const DtVector &v2);
314 DT_DLL_MATRIX DtVector operator-(const DtVector32& v1, const DtVector &v2);
315 DT_DLL_MATRIX DtVector operator-(const DtVector& v1, const DtVector32 &v2);
316 
318 DT_DLL_MATRIX void DtVecScale(const DtVector& v, double scale_factor, DtVector& result);
319 DT_DLL_MATRIX void DtVecScale(const DtVector32& v, double scale_factor, DtVector32& result);
320 DT_DLL_MATRIX void DtVecScale(const DtVector32& v, double scale_factor, DtVector& result);
321 
323 DT_DLL_MATRIX void DtVecNeg(const DtVector& v1, DtVector& result);
324 DT_DLL_MATRIX void DtVecNeg(const DtVector32& v1, DtVector32& result);
325 
328 DT_DLL_MATRIX double DtVecCosProd(const DtVector& v1, const DtVector& v2);
329 DT_DLL_MATRIX double DtVecCosProd(const DtVector32& v1, const DtVector32& v2);
330 
333 DT_DLL_MATRIX double DtVecBoxProd(const DtVector& v1, const DtVector& v2, const DtVector& v3);
334 DT_DLL_MATRIX double DtVecBoxProd(const DtVector32& v1, const DtVector32& v2, const DtVector32& v3);
335 
338 DT_DLL_MATRIX void DtVecDcmMul(const DtVector& v, const DtDcm& m, DtVector& result);
339 DT_DLL_MATRIX void DtVecDcmMul(const DtVector32& v, const DtDcm& m, DtVector32& result);
340 
342 DT_DLL_MATRIX void DtVV_Product(const DtVector& a,const DtVector& b, DtDcm& ans);
343 DT_DLL_MATRIX void DtVV_Product(const DtVector32& a,const DtVector32& b, DtDcm& ans);
344 
346 DT_DLL_MATRIX double DtVecInfNorm(const DtVector& v1);
347 DT_DLL_MATRIX double DtVecInfNorm(const DtVector32& v1);
348 
352 
357 
360 DT_DLL_MATRIX void DtVecCopy(const DtVector& from, DtVector& to);
361 DT_DLL_MATRIX void DtVecCopy(const DtVector32& from, DtVector32& to);
362 
365 DT_DLL_MATRIX int DtVecCheck(const DtVector& v);
366 DT_DLL_MATRIX int DtVecCheck(const DtVector32& v);
367 
370 DT_DLL_MATRIX void DtVecNormalize(const DtVector& v, DtVector& result);
371 DT_DLL_MATRIX void DtVecNormalize(const DtVector32& v, DtVector32& result);
372 
375 DT_DLL_MATRIX void DtVecCrossProd(const DtVector& v1, const DtVector& v2, DtVector& result);
376 DT_DLL_MATRIX void DtVecCrossProd(const DtVector& v1, const DtVector& v2, DtVector32& result);
377 DT_DLL_MATRIX void DtVecCrossProd(const DtVector32& v1, const DtVector32& v2, DtVector32& result);
378 
381 DT_DLL_MATRIX double DtVecDotProd(const DtVector& v1, const DtVector& v2);
382 DT_DLL_MATRIX double DtVecDotProd(const DtVector32& v1, const DtVector32& v2);
383 
386 DT_DLL_MATRIX void DtVecDump(const char *str, const DtVector& v);
387 DT_DLL_MATRIX void DtVecDump(const char *str, const DtVector32& v);
388 
391 DT_DLL_MATRIX void DtVecSub(const DtVector& v1, const DtVector& v2, DtVector& result);
392 DT_DLL_MATRIX void DtVecSub(const DtVector32& v1, const DtVector32& v2, DtVector32& result);
393 
396 DT_DLL_MATRIX void DtVecAdd(const DtVector& v1, const DtVector& v2, DtVector& result);
397 DT_DLL_MATRIX void DtVecAdd(const DtVector32& v1, const DtVector32& v2, DtVector32& result);
398 
403  const DtVector& b, double time);
405  const DtVector32& b, double time);
406 
410 DT_DLL_MATRIX double DtHeadingFromAToB(const DtVector& a, const DtVector& b);
411 DT_DLL_MATRIX double DtHeadingFromAToB(const DtVector32& a, const DtVector32& b);
412 
413 /* ||p1-p2||_{2} */
415 DT_DLL_MATRIX double DtDistance(const DtVector& p1, const DtVector& p2);
416 DT_DLL_MATRIX double DtDistance(const DtVector32& p1, const DtVector32& p2);
417 
419 DT_DLL_MATRIX double DtDistSqr(const DtVector& p1, const DtVector& p2);
420 DT_DLL_MATRIX double DtDistSqr(const DtVector32& p1, const DtVector32& p2);
421 
426 
427 
431 {
432 public:
433  DtNetVector32();
434  DtNetVector32(const DtVector32 &vec);
435  DtVector32 operator=(const DtVector32 &vec);
436  operator DtVector32() const;
437  DtNetFloat32 &operator[](int i);
438  DtNetFloat32 operator[](int i) const;
439 private:
440  DtNetFloat32 rep[3];
441 };
442 
446 {
447 public:
448  DtNetVector64();
449  DtNetVector64(const DtVector &vec);
450  DtVector operator=(const DtVector &vec);
451  operator DtVector() const;
452  DtNetFloat64 &operator[](int i);
453  DtNetFloat64 operator[](int i) const;
454 private:
455  DtNetFloat64 rep[3];
456 };
457 
458 template <typename T> std::ostream & operator << (std::ostream &str, const DtVectorT<T> &vec)
459 {
460  vec.printDataToStream(str);
461  return str;
462 };
463 
464 
466 #define vlVector_inl
467 #include "vlVector.inl"
468 #undef vlVector_inl
469 
470 #ifdef DtUSE_UTILITIES_NAMESPACE
471 }
472 #endif
473 
474 
double DtDistance(const DtVector &p1, const DtVector &p2)
const bool operator==(const DtU128 &lhs, const DtU128 &rhs)
DtVector DtLerpVector(DtVector va, DtVector vb, double t)
Initialize to all zeros.
double DtDistSqr(const DtVector &p1, const DtVector &p2)
void DtVecInit(DtVector &v)
Contains the DtString class declaration.
DtVector operator+(const DtVector &v1, const DtVector &v2)
implements v1 + v2
void DtVV_Product(const DtVector &a, const DtVector &b, DtDcm &ans)
double DtVecBoxProd(const DtVector &v1, const DtVector &v2, const DtVector &v3)
sweep v1 to v2 to v3
DtVector32 & DtVectorRef32
Definition: vlVector.h:289
DtVectors represent vectors in 3-d space, X, Y, Z.
Definition: vlVector.h:49
double DtVecCosProd(const DtVector &v1, const DtVector &v2)
result = -vec
Definition: vlVector.h:33
DtVector & DtVectorRef
Definition: vlVector.h:288
DtVector64 DtVector32To64(const DtVector32 &v32)
Convert between DtVector64 and DtVector32.
void DtVecSub(const DtVector &v1, const DtVector &v2, DtVector &result)
DtThreeIndex DtLevi_Civita
const DtVector & DtConstVector
Definition: vlVector.h:286
This file defines math constants and methods which may be useful in simulations.
Network-order 64-bit IEEE-754 floating-point quantity.
Definition: vlNetTypes.h:174
A Network Byte Order layout using 64 bit floats for DtVector.
Definition: vlVector.h:445
DtVector64 DtVector
Definition: vlVector.h:285
Definition: vlVector.h:224
Definition: vlVector.h:31
void DtVecCopy(const DtVector &from, DtVector &to)
double DtHeadingFromAToB(const DtVector &a, const DtVector &b)
Expects UTM coordinates.
Definition: vlVector.h:162
const DtVector32 & DtConstVector32
Definition: vlVector.h:287
#define DT_DLL_MATRIX
Definition: vlMachineTypes.h:107
DtVector32 DtVector64To32(const DtVector64 &v32)
DtVector DtVelocityFromAToB(const DtVector &a, const DtVector &b, double time)
DtVelocityFromAToB() Returns velocity you would need to be traveling at to get from point A to point ...
void DtVecDump(const char *str, const DtVector &v)
double DtVecInfNorm(const DtVector &v1)
void DtVecDcmMul(const DtVector &v, const DtDcm &m, DtVector &result)
Multiplies a vector by a matrix and stores the result.
double(* DtThreeIndexPtr)[3][3]
Definition: vlVector.h:292
DtVectorOffset
A simple enumeration to represent Vector Offsets.
Definition: vlVector.h:29
Definition: vlVector.h:32
DtVector operator-(const DtVector &v1, const DtVector &v2)
implemented v1 - v2
double DtVecDotProd(const DtVector &v1, const DtVector &v2)
void DtVecNeg(const DtVector &v1, DtVector &result)
void DtVecNormalize(const DtVector &v, DtVector &result)
DtDcms are used to represent orientation for an object.
Definition: vlDcm.h:39
void DtVecAdd(const DtVector &v1, const DtVector &v2, DtVector &result)
const bool operator!=(const DtU128 &lhs, const DtU128 &rhs)
void DtVecScale(const DtVector &v, double scale_factor, DtVector &result)
Network-order 32-bit IEEE-754 floating-point quantity.
Definition: vlNetTypes.h:148
Instances of DtString are used to represent strings.
Definition: vlString.h:36
double DtThreeIndex[3][3][3]
Definition: vlVector.h:291
int DtVecCheck(const DtVector &v)
void DtVecCrossProd(const DtVector &v1, const DtVector &v2, DtVector &result)
This file contains typedefs for machine dependant types.
A Network Byte Order layout using 32 bit floats for DtVector.
Definition: vlVector.h:430

Document ID: Generated on Thu Oct 16 00:12:25 EDT 2025 from SVN revision 280738
Copyright © 1992-2025 MAK Technologies. All Rights Reserved (www.mak.com)