1#ifndef RIVET_MATH_VECTOR2
2#define RIVET_MATH_VECTOR2
4#include "Rivet/Math/MathConstants.hh"
5#include "Rivet/Math/MathUtils.hh"
6#include "Rivet/Math/VectorN.hh"
28 class Vector2 :
public Vector<2> {
31 friend Vector2 multiply(
const double,
const Vector2&);
32 friend Vector2 multiply(
const Vector2&,
const double);
33 friend Vector2 add(
const Vector2&,
const Vector2&);
34 friend Vector2 subtract(
const Vector2&,
const Vector2&);
41 template <
typename V2TYPE>
42 Vector2(
const V2TYPE& other) {
43 this->setX(other.x());
44 this->setY(other.y());
47 Vector2(
const Vector<2>& other) {
48 this->setX(other.get(0));
49 this->setY(other.get(1));
52 Vector2(
double x,
double y) {
62 static Vector2 mkX() {
65 static Vector2 mkY() {
78 Vector2& setX(
double x) {
82 Vector2& setY(
double y) {
89 double dot(
const Vector2& v)
const {
90 return _vec.dot(v._vec);
94 double angle(
const Vector2& v)
const {
96 if (localDotOther > 1.0)
return 0.0;
97 if (localDotOther < -1.0)
return M_PI;
98 return acos(localDotOther);
108 return *
this * 1.0 / md;
119 Vector2& operator*=(
const double a) {
120 _vec = multiply(a, *
this)._vec;
124 Vector2& operator/=(
const double a) {
125 _vec = multiply(1.0 / a, *
this)._vec;
129 Vector2& operator+=(
const Vector2& v) {
130 _vec = add(*
this, v)._vec;
134 Vector2& operator-=(
const Vector2& v) {
135 _vec = subtract(*
this, v)._vec;
153 result._vec = a * v._vec;
158 return multiply(a, v);
162 return multiply(a, v);
166 return multiply(a, v);
170 return multiply(1.0 / a, v);
175 result._vec = a._vec + b._vec;
181 result._vec = a._vec - b._vec;
Two-dimensional specialisation of Vector.
Definition Vector2.hh:28
double dot(const Vector2 &v) const
Dot-product with another vector.
Definition Vector2.hh:89
Vector2 unit() const
Synonym for unitVec.
Definition Vector2.hh:112
Vector2 unitVec() const
Unit-normalized version of this vector.
Definition Vector2.hh:103
double angle(const Vector2 &v) const
Angle in radians to another vector.
Definition Vector2.hh:94
double mod() const
Definition VectorN.hh:99
Vector< N > & set(const size_t index, const double value)
Definition VectorN.hh:63
Vector< N > operator-() const
Definition VectorN.hh:106
Definition LHCbCommon.hh:9
double subtract(double a, double b, double tolerance=1e-5)
Subtract two numbers with FP fuzziness.
Definition MathUtils.hh:242
double add(double a, double b, double tolerance=1e-5)
Add two numbers with FP fuzziness.
Definition MathUtils.hh:248
double angle(const Vector2 &a, const Vector2 &b)
Angle (in radians) between two 2-vectors.
Definition Vector2.hh:194
std::enable_if_t< std::is_arithmetic_v< N1 > &&std::is_arithmetic_v< N2 >, bool > fuzzyLessEquals(N1 a, N2 b, double tolerance=1e-5)
Compare two floating point numbers for <= with a degree of fuzziness.
Definition MathUtils.hh:103