VR-Forces Development_Version Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DtLine2D.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2015 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 
40  inline DtVector2<T> startPoint() const;
41  inline void setStartPoint( const DtVector2<T> point );
43 
45 
46  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 
75  inline T angle() const;
77 
79 
80 
81  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  {
111  myStartPoint = orig.myStartPoint;
112  myEndPoint = orig.myEndPoint;
113  }
114 
115  template<class T>
117  {
118  if ( &rhs != this )
119  {
120  myStartPoint = rhs.myStartPoint;
121  myEndPoint = rhs.myEndPoint;
122  }
123  return *this;
124  }
125 
126  template<class T>
128  {
129  }
130 
131  template<class T>
133  {
134  return myStartPoint;
135  }
136 
137  template<class T>
139  {
140  myStartPoint = point;
141  }
142 
143  template<class T>
145  {
146  return myEndPoint;
147  }
148 
149  template<class T>
151  {
152  myEndPoint = point;
153  }
154 
155  template<class T>
156  void DtLine2D<T>::getLine( T& x1, T& y1, T& x2, T& y2 ) const
157  {
158  x1 = myStartPoint.x;
159  y1 = myStartPoint.y;
160  x2 = myEndPoint.x;
161  y2 = myEndPoint.y;
162  }
163 
164  template<class T>
165  void DtLine2D<T>::setLine( T x1, T y1, T x2, T y2 )
166  {
167  myStartPoint.x = x1;
168  myStartPoint.y = y1;
169  myEndPoint.x = x2;
170  myEndPoint.y = y2;
171  }
172 
173  template<class T>
175  {
176  p1 = myStartPoint;
177  p2 = myEndPoint;
178  }
179 
180  template<class T>
181  void DtLine2D<T>::setPoints( const DtVector2<T>& p1, const DtVector2<T>& p2 )
182  {
183  myStartPoint = p1;
184  myEndPoint = p2;
185  }
186 
187  template<class T>
188  T DtLine2D<T>::dX() const
189  {
190  return myEndPoint.x - myStartPoint.x;
191  }
192 
193  template<class T>
194  T DtLine2D<T>::dY() const
195  {
196  return myEndPoint.y - myStartPoint.y;
197  }
198 
199  template<class T>
201  {
202  return sqrt( lengthSquared() );
203  }
204 
205  template<class T>
207  {
208  T dx = dX();
209  T dy = dY();
210  return ( dx * dx ) + ( dy * dy );
211  }
212 
213  template<class T>
215  {
216  double rot = atan2( -dY(), dX() );
217  return DtModPerLo( static_cast<T>(rot), 0., M_2PI );
218  }
219 
220 
221  template<class T>
222  T DtLine2D<T>::angleTo( const DtLine2D<T>& line ) const
223  {
224  T ourAngle = angle();
225  T theirAngle = line.angle();
226  return DtModPerLo( (theirAngle - ourAngle), 0., M_2PI );
227  }
228 
229  template<class T>
231  {
232  T dx = dX();
233  T dy = dY();
234  return DtVector2<T>( myStartPoint.x + ( dx * t ), myStartPoint.y + ( dy * t ) );
235  }
236 } //namespace makVrv

Document ID: Generated on Mon Jul 4 01:00:18 EDT 2016 from SVN revision 166489
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)