ASCO Aerial Autonomy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
position.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <cmath>
4 
8 struct Position {
13  Position() : x(0), y(0), z(0) {}
21  Position(double x, double y, double z) : x(x), y(y), z(z) {}
22  double x;
23  double y;
24  double z;
25 
30  double norm() const {
31  return std::sqrt(std::pow(x, 2) + std::pow(y, 2) + std::pow(z, 2));
32  }
33 
41  bool operator==(const Position &p) const {
42  return (x == p.x && y == p.y && z == p.z);
43  }
51  bool operator!=(const Position &p) const { return !(*this == p); }
57  Position operator+(const Position &p) const {
58  return Position(p.x + this->x, p.y + this->y, p.z + this->z);
59  }
65  Position operator-(const Position &p) const {
66  return Position(this->x - p.x, this->y - p.y, this->z - p.z);
67  }
68 
74  Position operator*(const double &m) const {
75  return Position(this->x * m, this->y * m, this->z * m);
76  }
82  Position operator/(const double &m) const { return this->operator*(1. / m); }
83 };
Position operator/(const double &m) const
Divide by a scalar.
Definition: position.h:82
double y
y component in m
Definition: position.h:23
Position()
Implicit constructor Instantiate position to (0,0,0)m.
Definition: position.h:13
double x
x component in m
Definition: position.h:22
bool operator!=(const Position &p) const
Compare two positions.
Definition: position.h:51
Position(double x, double y, double z)
Explicit constructor.
Definition: position.h:21
double z
z component in m
Definition: position.h:24
Position operator*(const double &m) const
Multiply times a scalar.
Definition: position.h:74
Position operator+(const Position &p) const
Definition: position.h:57
bool operator==(const Position &p) const
Compare two positions.
Definition: position.h:41
Store 3D position.
Definition: position.h:8
Position operator-(const Position &p) const
Definition: position.h:65
double norm() const
Returns the norm of the vector.
Definition: position.h:30