65 explicit Point(
const std::vector<double> &p) {
69 else if (p.size() == 1)
71 else if (p.size() == 2) {
74 }
else if (p.size() == 3) {
94 std::string
printStr(
int nt = 0,
int lvl = 0)
const {
96 std::string tabS =
"";
97 for (
int i = 0; i < nt; i++)
100 std::ostringstream oss;
101 oss << tabS <<
"(" <<
d_x <<
", " <<
d_y <<
", " <<
d_z <<
")";
112 void print(
int nt = 0,
int lvl = 0)
const { std::cout <<
printStr(nt, lvl); }
164 auto l_sq = (is_unit ? 1. : this->
length() * this->
length());
176 auto l_sq = (is_unit ? 1. : this->
length() * this->
length());
236 return {lhs.
d_x + rhs, lhs.
d_y + rhs, lhs.
d_z + rhs};
246 return {lhs + rhs.
d_x, lhs + rhs.
d_y, lhs + rhs.
d_z};
256 return {lhs.
d_x - rhs, lhs.
d_y - rhs, lhs.
d_z - rhs};
266 return {lhs - rhs.
d_x, lhs - rhs.
d_y, lhs - rhs.
d_z};
Collection of methods useful in simulation.
A structure to represent 3d vectors.
double d_y
the y coordinate
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
friend Point operator/(Point lhs, const double rhs)
Division by scalar operator.
double dist(const Point &b) const
Computes the distance between a given point from this point.
friend Point operator*(Point lhs, const double rhs)
Scalar product operator.
Point(const std::vector< double > &p)
Constructor.
double d_z
the z coordinate
Point & operator*=(const Point &b)
Multiplication (pointwise/elementwise) operator.
Point & operator/=(const double b)
Division by scalar operator.
Point & operator*=(const double b)
Multiplication by scalar operator.
double & operator[](size_t i)
Access operator.
friend Point operator+(Point lhs, const double rhs)
Addition by scalar operator.
double dot(const Point &b) const
Computes the dot product of this vector with another point.
friend Point operator-(const double lhs, Point rhs)
Subtraction by scalar operator.
Point & operator+=(const double b)
Addition by scalar operator.
friend Point operator*(const double lhs, Point rhs)
Multiplication by scalar operator.
double length() const
Computes the Euclidean length of the vector.
Point project(const Point &b, bool is_unit=false) const
Computes projection of vector on this vector.
Point cross(const Point &b) const
Computes the cross product between this vector and given vector.
Point & operator+=(const Point &b)
Addition operator.
friend Point operator-(Point lhs, const double rhs)
Subtraction by scalar operator.
Point(T x, T y, T z)
Constructor.
const double & operator[](size_t i) const
Access operator.
friend Point operator+(Point lhs, const Point &rhs)
Addition operator.
friend Point operator+(const double lhs, Point rhs)
Addition by scalar operator.
friend double operator*(Point lhs, const Point rhs)
Multiplication (dot) operator.
double lengthSq() const
Computes the Euclidean length of the vector.
Point projectNormal(const Point &b, bool is_unit=false) const
Computes projection of vector on plane with normal as this vector.
Point & operator-=(const double b)
Subtraction by scalar operator.
Point & operator-=(const Point &b)
Subtraction operator.
double d_x
the x coordinate
Point(T x[3])
Constructor.
Point(const Point &p)
Copy constructor.
void print(int nt=0, int lvl=0) const
Prints the information about the object.
friend Point operator-(Point lhs, const Point &rhs)
Subtraction operator.