VR-Forces 4.10 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtVdcVector2D.h
Go to the documentation of this file.
1 /*********************************************************************
2 ** Copyright (c) 2010 MaK Technologies, Inc.
3 ** All rights reserved.
4 *********************************************************************/
5 #pragma once
6 
7 #include <vlutil/vlString.h>
8 #include <matrix/vlVector.h>
9 #include <iosfwd>
10 
12 
13 // \file DtVdcVector2D.h
14 // \brief DtVdcVector2D.h provides an implimentation of a 2D Vector class as well as
15 // many methods which operate on DtVdcVector2Ds.
16 namespace vrvControlToolkit
17 {
18 
20  {
23  };
24 
26 
27  typedef const DtVdcVector2D &DtVdcConstVector2D;
29 
30  // \brief DtVdcVector2Ds represent vectors in 2-d space, X, Y
31  //
32  // A DtVdcVector2D is the 2D equivalent of the 3D DtVector
34  {
35  public:
36 
37  DtVdcVector2D();
38 
39  // Construct from two doubles.
40  DtVdcVector2D( const double& x, const double& y );
41 
42  // destructor
43  ~DtVdcVector2D();
44 
45  // copy constructor
46  DtVdcVector2D(const DtVdcVector2D& vec);
47 
48  // assignment operator
49  DtVdcVector2D& operator=(const DtVdcVector2D& vec);
50 
51  // set Vector to all zeros
52  void setToZero();
53 
54  // @{
55  // gets/sets the x component of a Vector
56  const double& x() const;
57  void setX(const double& x);
58  // @}
59 
60  // @{
61  // gets/sets the y component of a Vector
62  const double& y() const;
63  void setY(const double& y);
64  // @}
65 
66  // adds other to this vector
67  DtVdcVector2D &operator+=(const DtVdcVector2D &other);
68 
69  // subtracts other from this vector (this - other)
70  DtVdcVector2D &operator-=(const DtVdcVector2D &other);
71 
72  // subtraction
73  DtVdcVector2D operator-(const DtVdcVector2D &other) const;
74 
75  // addition
76  DtVdcVector2D operator+(const DtVdcVector2D &other) const;
77 
78  // multiplies this vector by scalar
79  DtVdcVector2D operator*(float scale) const;
80 
81  // multiplies this vector by scalar
82  DtVdcVector2D& operator*=(float scale);
83 
84  // Get the value for the specified subscript. (int version)
85  double& operator[](int ind);
86 
87  // A const version to get the value for the specified subscript
88  double operator[](int ind) const;
89 
90  // Get the value for the specified subscript. (enum version)
91  double& operator[](DtVdcVector2DOffset ind);
92 
93  // a const version to get the value for the specified subscript. (enum version)
94  double operator[](DtVdcVector2DOffset ind) const;
95 
96  // Get whether another vector equals this vector. Warning: This
97  // operation compares floats of exact equality.
98  int operator==(const DtVdcVector2D& vec) const;
99 
100  // Get whether another vector does not equal this vector. Warning:
101  // this operation calles operator== which tests floats for exact equality
102  int operator!=(const DtVdcVector2D& vec) const;
103 
104  // Get a string representation of the vector.
105  DtString string() const;
106 
107  // Create a DtVector (with z==0) from a DtVdcVector2D
108  DtVector vector3D() const;
109 
110  // Get the magnitude of the vector squared,
111  // i.e. x^2 + y^2
112  double magnitudeSquared() const;
113 
114  // Normalize the vector; i.e., magnitude = 1.
115  void normalize();
116 
117  // Returns true of the vector is Normalized
118  bool isNormalized() const;
119 
120  // Compute dot product with another vector
121  double dotProduct(const DtVdcVector2D& v) const;
122 
123  // check if the vector is zero-ed out withing the tolerace passed
124  bool approxEq(const DtVdcVector2D& v, const double& tolerance) const;
125 
126  // check if the magnitide of this vector is zero
127  bool magnitudeIsZero() const;
128 
129  // check if the magnitide of this vector is zero, within the tolerance passed.
130  // \Note This tolerance is comparied against each component of the vector,
131  // not the magnitude.
132  bool magnitudeIsZero(double tolerance) const;
133 
134  // prints out a formated string to the stream
135  std::ostream &printDataToStream(std::ostream &str) const;
136 
137  public:
138 
139  // @name These functions reveal the internal representation of DtVector
140  // and should not be used. They are provided for backwards compatability
141  // @{
142  operator double* ();
143  operator const double* () const;
144  // @}
145 
146  public:
147 
148 
149  // Get a zero'ed vector.
150  static const DtVdcVector2D& zero();
151 
152  // Get a (1,0) vector.
153  static const DtVdcVector2D& i();
154 
155  // Get a (0,1) vector.
156  static const DtVdcVector2D& j();
157 
158  // Get a vector set to all ones.
159  static const DtVdcVector2D& ones();
160 
161 
162  protected:
163 
164  double myRep[2];
165 
166 
167  };
168 
169  //
170  // Vector routines.
171  //
172 
173 #define DtSetVec2D(v, x, y) v[DtSdcX]=x;v[DtSdcY]=y;
174 
175  DT_DLL_VRVDRAWCONTROL void DtVecScale(const DtVdcVector2D& v, double scale_factor, DtVdcVector2D& result);
176  DT_DLL_VRVDRAWCONTROL void DtVecNeg(const DtVdcVector2D& v1, DtVdcVector2D& result); // result = -vec
177 
178  // cos of angle between v1 and V2
179  DT_DLL_VRVDRAWCONTROL double DtVecCosProd(const DtVdcVector2D& v1, const DtVdcVector2D& v2);
180 
181  DT_DLL_VRVDRAWCONTROL double DtVecInfNorm(const DtVdcVector2D& v1);
182  DT_DLL_VRVDRAWCONTROL void DtVecInit(DtVdcVector2D& v); // Initialize to all zeros.
183 
184  /* ||p1-p2||_{2} */
185  DT_DLL_VRVDRAWCONTROL double DtDistance(const DtVdcVector2D& p1, const DtVdcVector2D& p2);
186 
187  DT_DLL_VRVDRAWCONTROL double DtDistSqr(const DtVdcVector2D& p1, const DtVdcVector2D& p2);
188 }
189 
190 std::ostream & operator << (std::ostream &str, const vrvControlToolkit::DtVdcVector2D &vec);
191 
192 
193 // Include inline definitions for vlVector
194 #define DtVdcVector2D_inl
195 #include <vrvDrawControl/DtVdcVector2D.inl>
196 #undef DtVdcVector2D_inl
197 
198 
DtVdcVector2DOffset
Definition: DtVdcVector2D.h:19
DT_DLL_VRVDRAWCONTROL double DtDistance(const DtVdcVector2D &p1, const DtVdcVector2D &p2)
DT_DLL_terrainCS bool operator==(const DtDegMinSec &lhs, const DtDegMinSec &rhs)
DT_DLL_features std::ostream & operator<<(std::ostream &, const DtFeatureTransform &)
std::ostream output.
DT_DLL_VRVDRAWCONTROL double DtVecInfNorm(const DtVdcVector2D &v1)
Definition: DtVdcVector2D.h:21
DT_DLL_VRVDRAWCONTROL double DtDistSqr(const DtVdcVector2D &p1, const DtVdcVector2D &p2)
const DtVdcVector2D & DtVdcConstVector2D
Definition: DtVdcVector2D.h:25
Definition: DtVdcVector2D.h:33
DT_DLL_VRVDRAWCONTROL void DtVecNeg(const DtVdcVector2D &v1, DtVdcVector2D &result)
DT_DLL_VRVDRAWCONTROL void DtVecScale(const DtVdcVector2D &v, double scale_factor, DtVdcVector2D &result)
DT_DLL_VRVDRAWCONTROL double DtVecCosProd(const DtVdcVector2D &v1, const DtVdcVector2D &v2)
#define DT_DLL_VRVDRAWCONTROL
Definition: vrvDrawControl.h:15
Definition: DtVdcVector2D.h:22
DT_DLL_terrainCS bool operator!=(const DtDegMinSec &lhs, const DtDegMinSec &rhs)
DT_DLL_VRVDRAWCONTROL void DtVecInit(DtVdcVector2D &v)
DtVdcVector2D & DtVdcVector2DRef
Definition: DtVdcVector2D.h:28

Document ID: Generated on Tue Sep 21 17:42:52 EDT 2021 from SVN revision 234861
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)