VR-Forces 5.0.1 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtLine2D.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2017 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 #pragma once
10 
12 #include <matrix/LibMatrix.h>
13 
14 namespace makVrv {
15 
21  template<class T>
22  class DtLine2D
23  {
24  public:
25 
27  DtLine2D( const DtVector2<T>& p1, const DtVector2<T>& p2 );
28 
30  DtLine2D( const DtLine2D<T>& orig );
31 
32  // Assignment Operator
33  DtLine2D<T>& operator=( const DtLine2D<T>& rhs );
34 
36  virtual ~DtLine2D();
37 
39  inline DtVector2<T> startPoint() const;
41  inline void setStartPoint( const DtVector2<T>& point );
43 
45  inline DtVector2<T> endPoint() const;
47  inline void setEndPoint( const DtVector2<T>& point );
49 
51  inline void getLine( T& x1, T& y1, T& x2, T& y2 ) const;
52  inline void setLine( T x1, T y1, T x2, T y2 );
54 
55  //{
57  inline void getPoints( DtVector2<T>& p1, DtVector2<T>& p2 ) const;
58  inline void setPoints( const DtVector2<T>& p1, const DtVector2<T>& p2 );
60 
62  inline T dX() const;
63 
65  inline T dY() const;
66 
68  inline T length() const;
69 
71  inline T lengthSquared() const;
72 
74  inline T angle() const;
77 
79  inline T angleTo( const DtLine2D<T>& line ) const;
83 
86  inline DtVector2<T> pointAt( T t );
87  private:
88 
90  DtLine2D();
91 
92  protected:
95  };
96 
97  //
98  // Template Class Definitions
99  //
100 
101  template<class T>
103  : myStartPoint( p1 )
104  , myEndPoint( p2 )
105  {
106  }
107 
108  template<class T>
110  : myStartPoint(orig.myStartPoint)
111  , myEndPoint(orig.myEndPoint)
112  {
113 
114  }
115 
116  template<class T>
118  {
119  if ( &rhs != this )
120  {
121  myStartPoint = rhs.myStartPoint;
122  myEndPoint = rhs.myEndPoint;
123  }
124  return *this;
125  }
126 
127  template<class T>
129  {
130  }
131 
132  template<class T>
134  {
135  return myStartPoint;
136  }
137 
138  template<class T>
140  {
141  myStartPoint = point;
142  }
143 
144  template<class T>
146  {
147  return myEndPoint;
148  }
149 
150  template<class T>
152  {
153  myEndPoint = point;
154  }
155 
156  template<class T>
157  void DtLine2D<T>::getLine( T& x1, T& y1, T& x2, T& y2 ) const
158  {
159  x1 = myStartPoint.x;
160  y1 = myStartPoint.y;
161  x2 = myEndPoint.x;
162  y2 = myEndPoint.y;
163  }
164 
165  template<class T>
166  void DtLine2D<T>::setLine( T x1, T y1, T x2, T y2 )
167  {
168  myStartPoint.x = x1;
169  myStartPoint.y = y1;
170  myEndPoint.x = x2;
171  myEndPoint.y = y2;
172  }
173 
174  template<class T>
176  {
177  p1 = myStartPoint;
178  p2 = myEndPoint;
179  }
180 
181  template<class T>
182  void DtLine2D<T>::setPoints( const DtVector2<T>& p1, const DtVector2<T>& p2 )
183  {
184  myStartPoint = p1;
185  myEndPoint = p2;
186  }
187 
188  template<class T>
189  T DtLine2D<T>::dX() const
190  {
191  return myEndPoint.x - myStartPoint.x;
192  }
193 
194  template<class T>
195  T DtLine2D<T>::dY() const
196  {
197  return myEndPoint.y - myStartPoint.y;
198  }
199 
200  template<class T>
202  {
203  return sqrt( lengthSquared() );
204  }
205 
206  template<class T>
208  {
209  T dx = dX();
210  T dy = dY();
211  return ( dx * dx ) + ( dy * dy );
212  }
213 
214  template<class T>
216  {
217  double rot = atan2( -dY(), dX() );
218  return DtModPerLo( static_cast<T>(rot), 0., M_2PI );
219  }
220 
221 
222  template<class T>
223  T DtLine2D<T>::angleTo( const DtLine2D<T>& line ) const
224  {
225  T ourAngle = angle();
226  T theirAngle = line.angle();
227  return DtModPerLo( (theirAngle - ourAngle), 0., M_2PI );
228  }
229 
230  template<class T>
232  {
233  T dx = dX();
234  T dy = dY();
235  return DtVector2<T>( myStartPoint.x + ( dx * t ), myStartPoint.y + ( dy * t ) );
236  }
237 } //namespace makVrv
T dX() const
Get the difference between x2 and x1.
Definition: DtLine2D.h:189
void getPoints(DtVector2< T > &p1, DtVector2< T > &p2) const
Get / set the line as points.
Definition: DtLine2D.h:175
T dY() const
Get the different between y2 and y1.
Definition: DtLine2D.h:195
2 dimensional vector
void setPoints(const DtVector2< T > &p1, const DtVector2< T > &p2)
Definition: DtLine2D.h:182
DtVector2< T > pointAt(T t)
Get the point along the line at the parametric value supplied (between 0. and 1. inclusive) ...
Definition: DtLine2D.h:231
DtLine2D< T > & operator=(const DtLine2D< T > &rhs)
Definition: DtLine2D.h:117
DtVector2< T > endPoint() const
Get / set the ending point of the line.
Definition: DtLine2D.h:145
DtLine2D class DtLine2D is a templated class (typically for doing floats vs. doubles) used to represe...
Definition: DtLine2D.h:22
void setEndPoint(const DtVector2< T > &point)
Get / set the ending point of the line.
Definition: DtLine2D.h:151
DT_DLL_vrfutil double angle(double vec1[3], double vec2[3])
T angle() const
Get the angle that the line makes with the horizontal, in radians.
Definition: DtLine2D.h:215
void setStartPoint(const DtVector2< T > &point)
Get / set the starting point of the line.
Definition: DtLine2D.h:139
T length() const
Get the length of the line.
Definition: DtLine2D.h:201
void setLine(T x1, T y1, T x2, T y2)
Definition: DtLine2D.h:166
DtLine2D()
Unimplemented CTOR.
DtVector2< T > myStartPoint
Definition: DtLine2D.h:93
DtVector2< T > startPoint() const
Get / set the starting point of the line.
Definition: DtLine2D.h:133
DtVector2< T > myEndPoint
Definition: DtLine2D.h:94
void getLine(T &x1, T &y1, T &x2, T &y2) const
Definition: DtLine2D.h:157
T lengthSquared() const
Get the length of the line squared.
Definition: DtLine2D.h:207
virtual ~DtLine2D()
DTOR.
Definition: DtLine2D.h:128
T angleTo(const DtLine2D< T > &line) const
Get the angle that rotates this into into the same angle as the supplied line, in radians...
Definition: DtLine2D.h:223
2 dimensional vector
Definition: DtMath.h:20

Document ID: Generated on Mon Jun 20 00:38:30 EDT 2022 from SVN revision 244029
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)