33 #include "MeshKernel/Constants.hpp"
42 Vector() : m_values{constants::missing::doubleValue, constants::missing::doubleValue} {}
48 Vector(
const double x,
const double y) : m_values{
x,
y} {}
52 [[nodiscard]]
double x()
const
59 [[nodiscard]]
double&
x()
66 [[nodiscard]]
double y()
const
72 [[nodiscard]]
double&
y()
114 std::array<double, 2> m_values;
123 double dot(
const Vector& v1,
const Vector& v2);
126 double angleBetween(
const Vector& v1,
const Vector& v2);
134 Vector
operator+(
const Vector& v1,
const Vector& v2);
137 Vector
operator-(
const Vector& v1,
const Vector& v2);
140 Vector
operator*(
const double alpha,
const Vector& vec);
143 Vector
operator*(
const Vector& vec,
const double alpha);
146 Vector
operator/(
const Vector& vec,
const double alpha);
162 m_values[0] += vec.m_values[0];
163 m_values[1] += vec.m_values[1];
169 m_values[0] -= vec.m_values[0];
170 m_values[1] -= vec.m_values[1];
176 m_values[0] /= alpha;
177 m_values[1] /= alpha;
183 m_values[0] *= alpha;
184 m_values[1] *= alpha;
190 double lengthInv = 1.0 / length();
191 m_values[0] *= lengthInv;
192 m_values[1] *= lengthInv;
198 return std::hypot(m_values[0], m_values[1]);
203 return m_values[0] * m_values[0] + m_values[1] * m_values[1];
208 double lengthInv = 1.0 / vec.
length();
209 Vector normalised(vec.
x() * lengthInv, vec.
y() * lengthInv);
215 return v1.
x() * v2.
x() + v1.
y() * v2.
y();
220 return std::atan2(v1.
y() * v2.
x() - v1.
x() * v2.
y(), v1.
x() * v2.
x() + v1.
y() * v2.
y());
230 return Vector(v1.
x() + v2.
x(), v1.
y() + v2.
y());
235 return Vector(v1.
x() - v2.
x(), v1.
y() - v2.
y());
240 return Vector(alpha * vec.
x(), alpha * vec.
y());
250 return Vector(vec.
x() / alpha, vec.
y() / alpha);
Vector & operator/=(const double alpha)
Inplace divide vector by scalar.
Definition: Vector.hpp:174
double & y()
Gets the y coordinate of the vector.
Definition: Vector.hpp:72
Vector()
Default constructor.
Definition: Vector.hpp:42
Cartesian3DPoint operator/(const Cartesian3DPoint &p, const double value)
Divide Cartesian point p by a scalar value.
Definition: Operations.hpp:634
double angleBetween(const Vector &v1, const Vector &v2)
Compute the angle between two vector.
Definition: Vector.hpp:218
A class defining a vector.
Definition: Vector.hpp:38
Cartesian3DPoint operator-(const Cartesian3DPoint &p1, const Cartesian3DPoint &p2)
Subtract Cartesian point p2 from p1.
Definition: Operations.hpp:629
Cartesian3DPoint operator*(const Cartesian3DPoint &p, const double value)
Multiply Cartesian point p by a scalar value.
Definition: Operations.hpp:644
double & x()
Gets the x coordinate of the vector.
Definition: Vector.hpp:59
double lengthSquared() const
Compute the length squared of the vector.
Definition: Vector.hpp:201
Vector & operator+=(const Vector &vec)
Inplace add vector to vector.
Definition: Vector.hpp:160
Contains the logic of the C++ static library.
Definition: AveragingInterpolation.hpp:36
double y() const
Gets the y coordinate of the vector.
Definition: Vector.hpp:66
std::uint32_t UInt
Integer type used when indexing mesh graph entities.
Definition: Definitions.hpp:38
Cartesian3DPoint operator+(const Cartesian3DPoint &p1, const Cartesian3DPoint &p2)
Add Cartesian point p2 to p1.
Definition: Operations.hpp:624
double length() const
Compute the length of the vector.
Definition: Vector.hpp:195
double x() const
Gets the x coordinate of the vector.
Definition: Vector.hpp:52
double dot(const Point &p1, const Point &p2)
Compute the dot product of two points.
Definition: Point.hpp:351
Vector & operator-=(const Vector &vec)
Inplace subtract vector from vector.
Definition: Vector.hpp:167
Vector(const double x, const double y)
Class constructor.
Definition: Vector.hpp:48
double operator[](const UInt i) const
Get the value of the vector.
Definition: Vector.hpp:150
void normalise()
Normalise the vector in place.
Definition: Vector.hpp:188
Vector & operator*=(const double alpha)
Inplace multiply vector by scalar.
Definition: Vector.hpp:181
Vector normalise(const Vector &vec)
Return the normalised vector.
Definition: Vector.hpp:206