Mobile API Reference  MicroStrategy 2019
Vector2D.h
Go to the documentation of this file.
1 //==============================================================================================
2 // FILENAME : TVector2D.h
3 // AUTHOR : Liang Liu
4 // CREATION : 2008-09-25
5 // Copyright (C) MicroStrategy Incorporated 2008
6 // All Rights Reserved
7 //==============================================================================================
8 
9 #ifndef MsiChart_Vector2D_h
10 #define MsiChart_Vector2D_h
11 
12 #include "Point2D.h"
13 #include "PDCHeader/PDCcmath"
14 
15 namespace MsiChart
16 {
20  template <class T = float>
21  class TVector2D
22  {
23  public:
29  TVector2D(double iX, double iY) : x(static_cast<T>(iX)), y(static_cast<T>(iY)){}
34  TVector2D(const Point2D& irPoint) : x(irPoint.x), y(irPoint.y){}
41  TVector2D(const Point2D& irStart, const Point2D& irEnd)
42  : x(static_cast<T>(irEnd.x - irStart.x)), y(static_cast<T>(irEnd.y - irStart.y)){}
43 
50  TVector2D(const FPoint2D& irStart, const FPoint2D& irEnd)
51  : x(static_cast<T>(irEnd.x - irStart.x)), y(static_cast<T>(irEnd.y - irStart.y)){}
52 
58  void Reset(T iX, T iY);
59 
64  T LengthSquared() const;
69  T Length() const;
75  double IncludedAngle(const TVector2D<T>& irVector) const;
81  T InnerProduct(const TVector2D<T>& irVector) const;
87  T CrossProduct(const TVector2D<T>& irVector) const;
88 
90  void Normalize();
91 
92  public:
93  T x;
94  T y;
95  };
98 
99  template <class T>
100  inline void TVector2D<T>::Reset(T iX, T iY)
101  {
102  x = iX;
103  y = iY;
104  }
105 
106  //get the square length of a vector
107  template <class T>
109  {
110  return x * x + y * y;
111  }
112 
113  //A . B
114  template <class T>
115  inline T TVector2D<T>::InnerProduct(const TVector2D<T>& irVector) const
116  {
117  return (x * irVector.x + y * irVector.y);
118  }
119 
120  //A X B
121  template <class T>
122  inline T TVector2D<T>::CrossProduct(const TVector2D<T>& irVector) const
123  {
124  return (x * irVector.y - y * irVector.x);
125  }
126 
127  template <class T>
128  double TVector2D<T>::IncludedAngle(const TVector2D<T>& irVector) const
129  {
130  double lTemp = InnerProduct(irVector) / (std::sqrt(LengthSquared() * irVector.LengthSquared()));
131  lTemp = (lTemp > 1.0f) ? 1.0f : lTemp;
132  lTemp = (lTemp < -1.0f) ? -1.0f : lTemp;
133  return std::acos(lTemp);
134  }
135 
136  template <class T>
138  {
139  return std::sqrt(LengthSquared());
140  }
141 
142  template <class T>
144  {
145  double lLength = Length();
146  x = static_cast<T>(x / lLength);
147  y = static_cast<T>(y / lLength);
148  }
149 }
150 #endif
Definition: Vector2D.h:21
TVector2D(const Point2D &irPoint)
Definition: Vector2D.h:34
void Reset(T iX, T iY)
Definition: Vector2D.h:100
T y
Y component of current vector.
Definition: Vector2D.h:94
void Normalize()
Normalize the current vector.
Definition: Vector2D.h:143
TVector2D(double iX, double iY)
Definition: Vector2D.h:29
TVector2D(const FPoint2D &irStart, const FPoint2D &irEnd)
Definition: Vector2D.h:50
TVector2D< float > Vector2D
Definition: Vector2D.h:96
double IncludedAngle(const TVector2D< T > &irVector) const
Definition: Vector2D.h:128
T Length() const
Definition: Vector2D.h:137
TVector2D< double > DVector2D
Definition: Vector2D.h:97
TVector2D(const Point2D &irStart, const Point2D &irEnd)
Definition: Vector2D.h:41
Definition: ABLPlot.h:21
T LengthSquared() const
Definition: Vector2D.h:108
T x
X component of current vector.
Definition: Vector2D.h:93
T CrossProduct(const TVector2D< T > &irVector) const
Definition: Vector2D.h:122
T InnerProduct(const TVector2D< T > &irVector) const
Definition: Vector2D.h:115