Hummingbird Framework
 All Classes Functions Variables Modules Pages
Vector3d.h
1 #ifndef HB_VECTOR_3D_H
2 #define HB_VECTOR_3D_H
3 #include <cmath>
4 #include "Vector2d.h"
5 #include "Math.h"
6 
7 namespace hb
8 {
14  class Vector3d
15  {
16  public:
17  double x;
18  double y;
19  double z;
20 
25  Vector3d(): x(0), y(0), z(0){};
32  Vector3d(double x, double y, double z): x(x), y(y), z(z){};
37  Vector3d(const Vector3d& v): x(v.x), y(v.y), z(v.z){};
42  Vector3d(const Vector2d& v): x(v.x), y(v.y), z(0){};
48  Vector3d(const Vector2d& v, double z): x(v.x), y(v.y), z(z){};
49 
55  Vector3d rotatedXZ(double degrees) const;
61  Vector3d rotatedXY(double degrees) const;
67  Vector3d rotatedYZ(double degrees) const;
68 
73  Vector3d multiply(const Vector3d& v) const
74  {return Vector3d(x * v.x, y * v.y, z * v.z);}
75 
80  double module() const
81  {return sqrt(pow(x, 2) + pow(y, 2));}
82 
88  {
89  Vector3d v = *this;
90  double module = this->module();
91  if (module != 0.)
92  {
93  v.x /= module;
94  v.y /= module;
95  v.z /= module;
96  }
97  return v;
98  }
99 
105  {return Vector2d(x, y);}
106  };
107 
108 }
109 
110 hb::Vector3d operator -(const hb::Vector3d& right);
111 hb::Vector3d& operator +=(hb::Vector3d& left, const hb::Vector3d& right);
112 hb::Vector3d& operator -=(hb::Vector3d& left, const hb::Vector3d& right);
113 hb::Vector3d operator +(const hb::Vector3d& left, const hb::Vector3d& right);
114 hb::Vector3d operator -(const hb::Vector3d& left, const hb::Vector3d& right);
115 hb::Vector3d operator *(const hb::Vector3d& left, double right);
116 hb::Vector3d operator *(double left, const hb::Vector3d& right);
117 hb::Vector3d& operator *=(hb::Vector3d& left, double right);
118 hb::Vector3d operator /(const hb::Vector3d& left, double right);
119 hb::Vector3d& operator /=(hb::Vector3d& left, double right);
120 bool operator ==(const hb::Vector3d& left, const hb::Vector3d& right);
121 bool operator !=(const hb::Vector3d& left, const hb::Vector3d& right);
122 #endif
Vector3d(double x, double y, double z)
Contruct a Vector2d from two doubles.
Definition: Vector3d.h:32
Vector3d multiply(const Vector3d &v) const
Multiply two vectors component by component.
Definition: Vector3d.h:73
Vector3d rotatedYZ(double degrees) const
Get the vector rotated over the YZ plane.
Vector3d rotatedXZ(double degrees) const
Get the vector rotated over the XZ plane.
Vector3d()
Default constructor.
Definition: Vector3d.h:25
Vector3d normalized() const
Get the vector normalied.
Definition: Vector3d.h:87
Vector3d(const Vector2d &v, double z)
Implicit cast from Vector2d setting the z component.
Definition: Vector3d.h:48
Vector3d rotatedXY(double degrees) const
Get the vector rotated over the XY plane.
A 3D vector.
Definition: Vector3d.h:14
Definition: Box2DPlugin.h:6
Vector2d xy()
Get the Vector2d formed by the x and y components of the Vector3d.
Definition: Vector3d.h:104
double z
z component of the vector.
Definition: Vector3d.h:19
double y
y component of the vector.
Definition: Vector3d.h:18
Vector3d(const Vector2d &v)
Implicit cast from Vector2d (z = 0).
Definition: Vector3d.h:42
A 2D vector.
Definition: Vector2d.h:14
Vector3d(const Vector3d &v)
Copy constructor.
Definition: Vector3d.h:37
double x
x component of the vector.
Definition: Vector3d.h:17
double module() const
Get the module of the Vector3d.
Definition: Vector3d.h:80