Version: SMASH-1.5
smash::ThreeVector Class Reference

#include <threevector.h>

The ThreeVector class represents a physical three-vector \( \vec{x} = (x_1,x_2,x_3)\) with the components \( x_1,x_2,x_3 \).

It is related to the classes FourVector and Angles, both of which can be converted into a ThreeVector using the 'threevec()' method.

Definition at line 30 of file threevector.h.

Collaboration diagram for smash::ThreeVector:
[legend]

Public Types

using iterator = std::array< double, 3 >::iterator
 iterates over the components More...
 
using const_iterator = std::array< double, 3 >::const_iterator
 iterates over the components More...
 

Public Member Functions

 ThreeVector ()
 default constructor (nulls all components) More...
 
 ThreeVector (double y1, double y2, double y3)
 copy constructor More...
 
double & operator[] (std::size_t i)
 access the component at offset i. More...
 
double operator[] (std::size_t i) const
 const overload of the above. More...
 
double x1 () const
 
void set_x1 (double x)
 set first component More...
 
double x2 () const
 
void set_x2 (double y)
 set second component More...
 
double x3 () const
 
void set_x3 (double z)
 set third component More...
 
double sqr () const
 
double abs () const
 
double get_phi () const
 
double get_theta () const
 
void rotate (double phi, double theta, double psi)
 Rotate vector by the given Euler angles phi, theta, psi. More...
 
void rotate_around_y (double theta)
 Rotate the vector around the y axis by the given angle theta. More...
 
void rotate_around_z (double theta)
 Rotate the vector around the z axis by the given angle theta. More...
 
void rotate_z_axis_to (ThreeVector &r)
 Rotate the z-axis onto the vector r. More...
 
ThreeVector operator- () const
 negation: Returns \(-\vec x\) More...
 
ThreeVector operator+= (const ThreeVector &v)
 increase this vector by \(\vec v: \vec x^\prime = \vec x + \vec v\) More...
 
ThreeVector operator-= (const ThreeVector &v)
 decrease this vector by \(\vec v: \vec x^\prime = \vec x - \vec v\) More...
 
ThreeVector operator*= (const double &a)
 scale this vector by \(a: \vec x^\prime = a \cdot \vec x\) More...
 
ThreeVector operator/= (const double &a)
 divide this vector by \(a: \vec x^\prime = \frac{1}{a} \cdot \vec x\) More...
 
bool operator== (const ThreeVector &rhs) const
 
bool operator!= (const ThreeVector &rhs) const
 
ThreeVector CrossProduct (const ThreeVector &b) const
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 const overload of the above More...
 
const_iterator end () const
 const overload of the above More...
 
const_iterator cbegin () const
 
const_iterator cend () const
 

Private Attributes

std::array< double, 3 > x_
 the internal storage of the components. More...
 

Member Typedef Documentation

◆ iterator

using smash::ThreeVector::iterator = std::array<double, 3>::iterator

iterates over the components

Definition at line 119 of file threevector.h.

◆ const_iterator

using smash::ThreeVector::const_iterator = std::array<double, 3>::const_iterator

iterates over the components

Definition at line 121 of file threevector.h.

Constructor & Destructor Documentation

◆ ThreeVector() [1/2]

smash::ThreeVector::ThreeVector ( )
inline

default constructor (nulls all components)

Definition at line 33 of file threevector.h.

33 : x_({0., 0., 0.}) {}
std::array< double, 3 > x_
the internal storage of the components.
Definition: threevector.h:146
Here is the caller graph for this function:

◆ ThreeVector() [2/2]

smash::ThreeVector::ThreeVector ( double  y1,
double  y2,
double  y3 
)
inline

copy constructor

Definition at line 36 of file threevector.h.

36 : x_({y1, y2, y3}) {}
std::array< double, 3 > x_
the internal storage of the components.
Definition: threevector.h:146

Member Function Documentation

◆ operator[]() [1/2]

double& smash::ThreeVector::operator[] ( std::size_t  i)
inline

access the component at offset i.

Definition at line 39 of file threevector.h.

39 { return x_[i]; }
std::array< double, 3 > x_
the internal storage of the components.
Definition: threevector.h:146

◆ operator[]() [2/2]

double smash::ThreeVector::operator[] ( std::size_t  i) const
inline

const overload of the above.

Definition at line 41 of file threevector.h.

41 { return x_[i]; }
std::array< double, 3 > x_
the internal storage of the components.
Definition: threevector.h:146

◆ x1()

double smash::ThreeVector::x1 ( ) const
inline
Returns
first component

Definition at line 155 of file threevector.h.

155 { return x_[0]; }
std::array< double, 3 > x_
the internal storage of the components.
Definition: threevector.h:146
Here is the caller graph for this function:

◆ set_x1()

void smash::ThreeVector::set_x1 ( double  x)
inline

set first component

Definition at line 157 of file threevector.h.

157 { x_[0] = x; }
std::array< double, 3 > x_
the internal storage of the components.
Definition: threevector.h:146
Here is the caller graph for this function:

◆ x2()

double smash::ThreeVector::x2 ( ) const
inline
Returns
second component

Definition at line 159 of file threevector.h.

159 { return x_[1]; }
std::array< double, 3 > x_
the internal storage of the components.
Definition: threevector.h:146
Here is the caller graph for this function:

◆ set_x2()

void smash::ThreeVector::set_x2 ( double  y)
inline

set second component

Definition at line 161 of file threevector.h.

161 { x_[1] = y; }
std::array< double, 3 > x_
the internal storage of the components.
Definition: threevector.h:146
Here is the caller graph for this function:

◆ x3()

double smash::ThreeVector::x3 ( ) const
inline
Returns
third component

Definition at line 163 of file threevector.h.

163 { return x_[2]; }
std::array< double, 3 > x_
the internal storage of the components.
Definition: threevector.h:146
Here is the caller graph for this function:

◆ set_x3()

void smash::ThreeVector::set_x3 ( double  z)
inline

set third component

Definition at line 165 of file threevector.h.

165 { x_[2] = z; }
std::array< double, 3 > x_
the internal storage of the components.
Definition: threevector.h:146
Here is the caller graph for this function:

◆ sqr()

double smash::ThreeVector::sqr ( ) const
inline
Returns
the square of the vector (which is a scalar)

Definition at line 249 of file threevector.h.

249 { return (*this) * (*this); }
Here is the caller graph for this function:

◆ abs()

double smash::ThreeVector::abs ( ) const
inline
Returns
the absolute value

Definition at line 251 of file threevector.h.

251 { return std::sqrt((*this) * (*this)); }
Here is the caller graph for this function:

◆ get_phi()

double smash::ThreeVector::get_phi ( ) const
inline
Returns
the azimuthal angle phi

Definition at line 253 of file threevector.h.

253  {
254  if (std::abs(x1()) < really_small && std::abs(x2()) < really_small) {
255  return 0.;
256  } else {
257  return std::atan2(x2(), x1());
258  }
259 }
constexpr double really_small
Numerical error tolerance.
Definition: constants.h:34
double x1() const
Definition: threevector.h:155
double x2() const
Definition: threevector.h:159
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_theta()

double smash::ThreeVector::get_theta ( ) const
inline
Returns
the polar angle theta

Definition at line 261 of file threevector.h.

261  {
262  double r = abs();
263  return (r > 0.) ? std::acos(x3() / r) : 0.;
264 }
double x3() const
Definition: threevector.h:163
double abs() const
Definition: threevector.h:251
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rotate()

void smash::ThreeVector::rotate ( double  phi,
double  theta,
double  psi 
)
inline

Rotate vector by the given Euler angles phi, theta, psi.

If we assume the standard basis x, y, z then this means applying the matrix for a rotation of phi about z, followed by the matrix for a rotation theta about the rotated x axis. Last, psi is a rotation about the rotated z axis.

Parameters
[in]phiangle by which the first rotation is done about z axis.
[in]thetaangle by which the second rotation is done about the rotated x axis.
[in]psiangle by which the third rotation is done about the rotated z axis.

Euler angles are used to make rotation of several (different) position vectors belonging to one rigid body easy. A ThreeVector could be rotated via only two angles, but then the angles for rotating a rigid body consisting of multiple particles would require a different pair of rotation angles for every position.

Definition at line 266 of file threevector.h.

266  {
267  // Compute the cosine and sine for each angle.
268  const double cos_phi = std::cos(phi);
269  const double sin_phi = std::sin(phi);
270  const double cos_theta = std::cos(theta);
271  const double sin_theta = std::sin(theta);
272  const double cos_psi = std::cos(psi);
273  const double sin_psi = std::sin(psi);
274  // Get original coordinates.
275  std::array<double, 3> x_old = x_;
276  // Compute new coordinates.
277  x_[0] = (cos_phi * cos_psi - sin_phi * cos_theta * sin_psi) * x_old[0] +
278  (sin_phi * cos_psi + cos_phi * cos_theta * sin_psi) * x_old[1] +
279  sin_theta * sin_psi * x_old[2];
280  x_[1] = (-cos_phi * sin_psi - sin_phi * cos_theta * cos_psi) * x_old[0] +
281  (-sin_phi * sin_psi + cos_phi * cos_theta * cos_psi) * x_old[1] +
282  sin_theta * cos_psi * x_old[2];
283  x_[2] = sin_phi * sin_theta * x_old[0] - cos_phi * sin_theta * x_old[1] +
284  cos_theta * x_old[2];
285 }
std::array< double, 3 > x_
the internal storage of the components.
Definition: threevector.h:146
Here is the caller graph for this function:

◆ rotate_around_y()

void smash::ThreeVector::rotate_around_y ( double  theta)
inline

Rotate the vector around the y axis by the given angle theta.

Parameters
[in]thetaangle by which the rotation is done about y axis.

Definition at line 287 of file threevector.h.

287  {
288  const double cost = std::cos(theta);
289  const double sint = std::sin(theta);
290  // Get original coordinates.
291  std::array<double, 3> x_old = x_;
292  // Compute new coordinates.
293  x_[0] = cost * x_old[0] + sint * x_old[2];
294  // x_[1] is unchanged
295  x_[2] = -sint * x_old[0] + cost * x_old[2];
296 }
std::array< double, 3 > x_
the internal storage of the components.
Definition: threevector.h:146
Here is the caller graph for this function:

◆ rotate_around_z()

void smash::ThreeVector::rotate_around_z ( double  theta)
inline

Rotate the vector around the z axis by the given angle theta.

Parameters
[in]thetaangle by which the rotation is done about z axis.

Definition at line 298 of file threevector.h.

298  {
299  const double cost = std::cos(theta);
300  const double sint = std::sin(theta);
301  // Get original coordinates.
302  std::array<double, 3> x_old = x_;
303  // Compute new coordinates.
304  x_[0] = cost * x_old[0] - sint * x_old[1];
305  x_[1] = sint * x_old[0] + cost * x_old[1];
306  // x_[2] is unchanged
307 }
std::array< double, 3 > x_
the internal storage of the components.
Definition: threevector.h:146
Here is the caller graph for this function:

◆ rotate_z_axis_to()

void smash::ThreeVector::rotate_z_axis_to ( ThreeVector r)
inline

Rotate the z-axis onto the vector r.

Parameters
[in]rdirection in which new new z-axis is aligned

Definition at line 309 of file threevector.h.

309  {
310  rotate_around_y(r.get_theta());
311  rotate_around_z(r.get_phi());
312 }
void rotate_around_y(double theta)
Rotate the vector around the y axis by the given angle theta.
Definition: threevector.h:287
void rotate_around_z(double theta)
Rotate the vector around the z axis by the given angle theta.
Definition: threevector.h:298
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator-()

ThreeVector smash::ThreeVector::operator- ( ) const
inline

negation: Returns \(-\vec x\)

Definition at line 167 of file threevector.h.

167  {
168  ThreeVector neg(-x_[0], -x_[1], -x_[2]);
169  return neg;
170 }
std::array< double, 3 > x_
the internal storage of the components.
Definition: threevector.h:146
ThreeVector()
default constructor (nulls all components)
Definition: threevector.h:33

◆ operator+=()

ThreeVector smash::ThreeVector::operator+= ( const ThreeVector v)
inline

increase this vector by \(\vec v: \vec x^\prime = \vec x + \vec v\)

Definition at line 172 of file threevector.h.

172  {
173  x_[0] += v.x_[0];
174  x_[1] += v.x_[1];
175  x_[2] += v.x_[2];
176  return *this;
177 }
std::array< double, 3 > x_
the internal storage of the components.
Definition: threevector.h:146

◆ operator-=()

ThreeVector smash::ThreeVector::operator-= ( const ThreeVector v)
inline

decrease this vector by \(\vec v: \vec x^\prime = \vec x - \vec v\)

Definition at line 185 of file threevector.h.

185  {
186  x_[0] -= v.x_[0];
187  x_[1] -= v.x_[1];
188  x_[2] -= v.x_[2];
189  return *this;
190 }
std::array< double, 3 > x_
the internal storage of the components.
Definition: threevector.h:146

◆ operator*=()

ThreeVector smash::ThreeVector::operator*= ( const double &  a)
inline

scale this vector by \(a: \vec x^\prime = a \cdot \vec x\)

Definition at line 198 of file threevector.h.

198  {
199  x_[0] *= a;
200  x_[1] *= a;
201  x_[2] *= a;
202  return *this;
203 }
std::array< double, 3 > x_
the internal storage of the components.
Definition: threevector.h:146

◆ operator/=()

ThreeVector smash::ThreeVector::operator/= ( const double &  a)
inline

divide this vector by \(a: \vec x^\prime = \frac{1}{a} \cdot \vec x\)

Definition at line 235 of file threevector.h.

235  {
236  const double a_inv = 1.0 / a;
237  x_[0] *= a_inv;
238  x_[1] *= a_inv;
239  x_[2] *= a_inv;
240  return *this;
241 }
std::array< double, 3 > x_
the internal storage of the components.
Definition: threevector.h:146

◆ operator==()

bool smash::ThreeVector::operator== ( const ThreeVector rhs) const
inline
Returns
whether the vector is identical to another vector

Definition at line 109 of file threevector.h.

109 { return x_ == rhs.x_; }
std::array< double, 3 > x_
the internal storage of the components.
Definition: threevector.h:146

◆ operator!=()

bool smash::ThreeVector::operator!= ( const ThreeVector rhs) const
inline
Returns
whether the vector is different from another vector

Definition at line 111 of file threevector.h.

111 { return x_ != rhs.x_; }
std::array< double, 3 > x_
the internal storage of the components.
Definition: threevector.h:146

◆ CrossProduct()

ThreeVector smash::ThreeVector::CrossProduct ( const ThreeVector b) const
inline
Returns
cross product of this vector and another vector \( \vec{this} \times \vec{b} \)
cross product of two three-vectors \( \vec{a} \times \vec{b} \)

Definition at line 229 of file threevector.h.

229  {
230  return ThreeVector(x_[1] * b.x3() - x_[2] * b.x2(),
231  x_[2] * b.x1() - x_[0] * b.x3(),
232  x_[0] * b.x2() - x_[1] * b.x1());
233 }
std::array< double, 3 > x_
the internal storage of the components.
Definition: threevector.h:146
ThreeVector()
default constructor (nulls all components)
Definition: threevector.h:33
Here is the call graph for this function:

◆ begin() [1/2]

iterator smash::ThreeVector::begin ( )
inline
Returns
an iterator starting at the 0th component.

The iterator implements the randomIterator concept. Thus, you can simply write begin() + 1 to get an iterator that points to the 1st component.

Definition at line 129 of file threevector.h.

129 { return x_.begin(); }
std::array< double, 3 > x_
the internal storage of the components.
Definition: threevector.h:146

◆ end() [1/2]

iterator smash::ThreeVector::end ( )
inline
Returns
an iterator pointing after the 4th component.

Definition at line 132 of file threevector.h.

132 { return x_.end(); }
std::array< double, 3 > x_
the internal storage of the components.
Definition: threevector.h:146

◆ begin() [2/2]

const_iterator smash::ThreeVector::begin ( ) const
inline

const overload of the above

Definition at line 135 of file threevector.h.

135 { return x_.begin(); }
std::array< double, 3 > x_
the internal storage of the components.
Definition: threevector.h:146

◆ end() [2/2]

const_iterator smash::ThreeVector::end ( ) const
inline

const overload of the above

Definition at line 137 of file threevector.h.

137 { return x_.end(); }
std::array< double, 3 > x_
the internal storage of the components.
Definition: threevector.h:146

◆ cbegin()

const_iterator smash::ThreeVector::cbegin ( ) const
inline
See also
begin

Definition at line 140 of file threevector.h.

140 { return x_.cbegin(); }
std::array< double, 3 > x_
the internal storage of the components.
Definition: threevector.h:146

◆ cend()

const_iterator smash::ThreeVector::cend ( ) const
inline
See also
end

Definition at line 142 of file threevector.h.

142 { return x_.cend(); }
std::array< double, 3 > x_
the internal storage of the components.
Definition: threevector.h:146

Member Data Documentation

◆ x_

std::array<double, 3> smash::ThreeVector::x_
private

the internal storage of the components.

Definition at line 146 of file threevector.h.


The documentation for this class was generated from the following file: