Hybrid A* Planner
 All Classes Namespaces Files Functions Variables Friends Pages
vector2d.h
1 #ifndef VECTOR2D
2 #define VECTOR2D
3 
4 #include <iostream>
5 namespace HybridAStar {
6 //###################################################
7 // VECTOR2
8 //###################################################
10 class Vector2D {
11  public:
13  inline Vector2D(const float x = 0, const float y = 0) { this->x = x; this->y = y; }
15  inline Vector2D operator * (const float k) const { return Vector2D(x * k, y * k); }
17  inline Vector2D operator / (const float k) const { return Vector2D(x / k, y / k); }
19  inline Vector2D operator + (const Vector2D& b) const { return Vector2D(x + b.x, y + b.y); }
21  inline Vector2D operator - (const Vector2D& b) const { return Vector2D(x - b.x, y - b.y); }
23  inline Vector2D operator - () const {return Vector2D(-x, -y);}
25  friend std::ostream& operator<<(std::ostream& os, const Vector2D& b) {os << "(" << b.x << "|" << b.y << ")"; return os; }
27  float length() const { return std::sqrt(std::pow(x, 2) + std::pow(y, 2)); }
29  float sqlength() const { return x*x + y*y; }
31  float dot(Vector2D b) { return x * b.x + y * b.y; }
33  inline Vector2D ort(Vector2D b) {
34  Vector2D a(this->x, this->y);
35  Vector2D c;
36  // multiply b by the dot product of this and b then divide it by b's length
37  c = a - b * a.dot(b) / b.sqlength();
38  return c;
39  }
40  inline float getX() { return x; }
41  inline float getY() { return y; }
42  // void setT(float t) { this->t = t; }
43  // float getT() { return t; }
44  private:
46  float x;
48  float y;
49  // /// the theta part for plotting purposes
50  // float t;
51 };
52 inline Vector2D operator * (double k, const Vector2D& b) {
53  return (b * k);
54 }
55 }
56 #endif // VECTOR2D
Vector2D operator-() const
a method to negate a vector
Definition: vector2d.h:23
Vector2D(const float x=0, const float y=0)
default constructor
Definition: vector2d.h:13
Vector2D operator*(const float k) const
a method to multiply a vector by a scalar
Definition: vector2d.h:15
float y
the y part of the vector
Definition: vector2d.h:48
float length() const
a method to calculate the length of the vector
Definition: vector2d.h:27
friend std::ostream & operator<<(std::ostream &os, const Vector2D &b)
a convenience method to print a vector
Definition: vector2d.h:25
float dot(Vector2D b)
a method to calculate the dot product of two vectors
Definition: vector2d.h:31
A class describing a simple 2D vector.
Definition: vector2d.h:10
Vector2D operator+(const Vector2D &b) const
a method to add a vector to a vector
Definition: vector2d.h:19
Vector2D ort(Vector2D b)
a method that returns the orthogonal complement of two vectors
Definition: vector2d.h:33
float x
the x part of the vector
Definition: vector2d.h:46
Vector2D operator/(const float k) const
a method to divide a vector by a scalar
Definition: vector2d.h:17
float sqlength() const
a method to calculate the length of the vector
Definition: vector2d.h:29