1 #ifndef RIVET_MATH_VECTOR3
2 #define RIVET_MATH_VECTOR3
4 #include "Rivet/Math/MathHeader.hh"
5 #include "Rivet/Math/MathUtils.hh"
6 #include "Rivet/Math/VectorN.hh"
12 typedef Vector3 ThreeVector;
15 Vector3 multiply(
const double,
const Vector3&);
16 Vector3 multiply(
const Vector3&,
const double);
17 Vector3 add(
const Vector3&,
const Vector3&);
18 Vector3 operator*(
const double,
const Vector3&);
19 Vector3 operator*(
const Vector3&,
const double);
20 Vector3 operator/(
const Vector3&,
const double);
21 Vector3 operator+(
const Vector3&,
const Vector3&);
22 Vector3 operator-(
const Vector3&,
const Vector3&);
39 this->setX(other.x());
40 this->setY(other.y());
41 this->setZ(other.z());
45 this->setX(other.get(0));
46 this->setY(other.get(1));
47 this->setZ(other.get(2));
50 Vector3(
double x,
double y,
double z) {
64 double x()
const {
return get(0); }
65 double y()
const {
return get(1); }
66 double z()
const {
return get(2); }
67 Vector3& setX(
double x) {
set(0, x);
return *
this; }
68 Vector3& setY(
double y) {
set(1, y);
return *
this; }
69 Vector3& setZ(
double z) {
set(2, z);
return *
this; }
71 double dot(
const Vector3& v)
const {
72 return _vec.dot(v._vec);
77 result._vec = _vec.cross(v._vec);
81 double angle(
const Vector3& v)
const {
82 double localDotOther =
unit().dot(v.
unit());
84 return acos( localDotOther );
89 if (
isZero())
return *
this;
90 else return *
this * 1.0/this->
mod();
93 double polarRadius2()
const {
94 return x()*x() + y()*y();
99 return polarRadius2();
104 return polarRadius2();
107 double polarRadius()
const {
108 return sqrt(polarRadius2());
113 return polarRadius();
118 return polarRadius();
127 double value = atan2( y(), x() );
128 if (value > 2*
PI || value < -2*
PI){
129 value = fmod(value, 2*
PI);
131 if (value <= -
PI) value += 2*
PI;
132 if (value >
PI) value -= 2*
PI;
137 assert(value > -
PI && value <=
PI);
141 assert(value >= 0 && value < 2*
PI);
147 value = 2*
PI + value;
148 assert(value >= 0 && value < 2*
PI);
152 throw std::runtime_error(
"The specified phi mapping scheme is not yet implemented");
164 double polarangle = atan2(polarRadius(), z());
165 assert(polarangle >= -
PI && polarangle <=
PI);
186 Vector3& operator*=(
const double a) {
187 _vec = multiply(a, *
this)._vec;
191 Vector3& operator/=(
const double a) {
192 _vec = multiply(1.0/a, *
this)._vec;
196 Vector3& operator+=(
const Vector3& v) {
197 _vec = add(*
this, v)._vec;
201 Vector3& operator-=(
const Vector3& v) {
202 _vec = subtract(*
this, v)._vec;
216 inline double dot(
const Vector3& a,
const Vector3& b) {
220 inline Vector3 cross(
const Vector3& a,
const Vector3& b) {
224 inline Vector3 multiply(
const double a,
const Vector3& v) {
226 result._vec = a * v._vec;
230 inline Vector3 multiply(
const Vector3& v,
const double a) {
231 return multiply(a, v);
234 inline Vector3 operator*(
const double a,
const Vector3& v) {
235 return multiply(a, v);
238 inline Vector3 operator*(
const Vector3& v,
const double a) {
239 return multiply(a, v);
242 inline Vector3 operator/(
const Vector3& v,
const double a) {
243 return multiply(1.0/a, v);
246 inline Vector3 add(
const Vector3& a,
const Vector3& b) {
248 result._vec = a._vec + b._vec;
252 inline Vector3 subtract(
const Vector3& a,
const Vector3& b) {
254 result._vec = a._vec - b._vec;
258 inline Vector3 operator+(
const Vector3& a,
const Vector3& b) {
262 inline Vector3 operator-(
const Vector3& a,
const Vector3& b) {
263 return subtract(a, b);
275 return v.polarRadius2();
288 return v.polarRadius();
307 return v.
phi(mapping);
340 inline double deltaEta(
const Vector3& v,
double eta2) {
345 inline double deltaEta(
double eta1,
const Vector3& v) {
361 inline double deltaPhi(
const Vector3& v,
double phi2) {
366 inline double deltaPhi(
double phi1,
const Vector3& v) {
383 inline double deltaR(
const Vector3& v,
double eta2,
double phi2) {
388 inline double deltaR(
double eta1,
double phi1,
const Vector3& v) {