VR-Forces 4.5 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  : 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

Document ID: Generated on Thu Mar 23 18:54:12 EDT 2017 from SVN revision 174804
Copyright © 2005-2017 VT MÄK. All Rights Reserved (www.mak.com)