CSCI3081W Drone Delivery System
vector3.h
1 #ifndef VECTOR3_H_
2 #define VECTOR3_H_
3 
4 #include <cmath>
5 #include <iostream>
6 #include <vector>
7 
12 class Vector3 {
13  public:
14  double x = 0;
15  double y = 0;
16  double z = 0;
17 
22 
28  Vector3(double a);
29 
37  Vector3(double a, double b, double c);
38 
44  Vector3(const std::vector<double>& v);
45 
51  Vector3(const std::vector<float>& v);
52 
58  bool operator==(const Vector3& v) const;
59 
65  double& operator[](int i);
66 
72  double operator[](int i) const;
73 
80  Vector3 operator+(const Vector3& v) const;
81 
88  Vector3 operator-(const Vector3& v) const;
89 
97  Vector3 operator*(double s) const;
98 
105  Vector3 operator/(double s) const;
106 
112  double operator*(const Vector3& v) const;
113 
119  template <class T>
120  std::vector<T> vec() const {
121  return {static_cast<T>(x), static_cast<T>(y), static_cast<T>(z)};
122  }
123 
129  Vector3 cross(const Vector3& v) const;
130 
134  double magnitude() const;
135 
140 
144  Vector3 unit() const;
145 
150  double dist(const Vector3& v) const;
151 
157  friend std::ostream& operator<<(std::ostream& strm, const Vector3& v);
158 };
159 
160 #endif
a simple class used for vector math, most function are self explanatory
Definition: vector3.h:12
Vector3()
Default constructor.
Vector3 & normalize()
Normalizes the Vector3 object.
Vector3 unit() const
Normalizes the vector in the same direction.
bool operator==(const Vector3 &v) const
Overrides comparison operator.
Vector3 operator*(double s) const
Overrides * operator.
Vector3(double a, double b, double c)
Parameter constructor.
double operator*(const Vector3 &v) const
Dot product.
Vector3 operator+(const Vector3 &v) const
Overrides + operator.
double magnitude() const
Returns the magnitude of the Vector3 object.
std::vector< T > vec() const
return std::vector version of this Vector3 template function should be defined in same file with temp...
Definition: vector3.h:120
double & operator[](int i)
Overrides indexing operator.
Vector3 operator/(double s) const
Overrides / operator.
double operator[](int i) const
Overrides const indexing operator.
double dist(const Vector3 &v) const
Finds the distance between two vectors.
Vector3 operator-(const Vector3 &v) const
Overrides - operator.
Vector3(const std::vector< float > &v)
Parameter constructor.
friend std::ostream & operator<<(std::ostream &strm, const Vector3 &v)
<< operator for Vector3 objects
Vector3(double a)
Parameter constructor.
Vector3 cross(const Vector3 &v) const
Cross product.
Vector3(const std::vector< double > &v)
Parameter constructor.