Loading...
Searching...
No Matches
BALL::TVector3< T > Class Template Reference

`#include <BALL/MATHS/vector3.h>`

## Public Member Functions

Constructors and Destructors
| TVector3 ()
| TVector3 (const T *ptr)
| TVector3 (const T &value)
template<typename T2>
| TVector3 (const TVector3< T2 > &vec)
| TVector3 (const T &vx, const T &vy, const T &vz)
| TVector3 (const TVector3 &vector)
| TVector3 (const T &r, const TAngle< T > &phi, const TAngle< T > &theta)
| ~TVector3 ()
void | clear ()
Arithmetic operators
const TVector3 & | operator+ () const
TVector3 | operator- () const
TVector3 | operator+ (const TVector3 &b) const
TVector3 | operator- (const TVector3 &b) const
TVector3 & | operator+= (const TVector3 &vector)
TVector3 & | operator-= (const TVector3 &vector)
TVector3 | operator* (const T &scalar) const
TVector3 & | operator*= (const T &scalar)
TVector3 | operator/ (const T &lambda) const
TVector3 & | operator/= (const T &lambda)
T | operator* (const TVector3 &vector) const
TVector3 | operator% (const TVector3 &vector) const
TVector3 & | operator%= (const TVector3 &vector)
Predicates
bool | operator== (const TVector3 &vector) const
bool | operator!= (const TVector3 &vector) const
bool | operator< (const TVector3 &vector) const
| Needed for MSVC.
bool | isZero () const
bool | isOrthogonalTo (const TVector3 &vector) const
Storable Interface
void | write (PersistenceManager &pm) const
bool | read (PersistenceManager &pm)
Debugging and Diagnostics
void | dump (std::ostream &s=std::cout, Size depth=0) const
bool | isValid () const
Global binary operators for three-dimensional vectors.
template<typename T2>
BALL_INLINE | TVector3 (const TVector3< T2 > &vec)

## Vector components

For easier access, the three components of the vector are public members.
T | x
T | y
T | z

## Assignment

void | set (const T *ptr)
void | set (const T &value)
void | set (const T &vx, const T &vy, const T &vz)
void | set (const TVector3 &vector)
void | set (const T &r, const TAngle< T > &phi, const TAngle< T > &theta)
TVector3 & | operator= (const TVector3 &v)
TVector3 & | operator= (T value)
TVector3 & | operator= (const T *ptr)
void | get (T *ptr) const
void | get (T &x, T &y, T &z) const
void | get (TVector3 &vector) const
void | get (T &r, TAngle< T > &phi, TAngle< T > &theta) const
void | swap (TVector3 &vector)
T | getLength () const
T | getSquareLength () const
TVector3 & | normalize ()
TVector3 & | negate ()
T & | operator[] (Position position)
const T & | operator[] (Position position) const
static const TVector3 & | getZero ()
static const TVector3 & | getUnit ()

## Geometric properties

T | getDistance (const TVector3 &vector) const
T | getSquareDistance (const TVector3 &vector) const
TAngle< T > | getAngle (const TVector3 &vector) const
TVector3 | getOrthogonalProjection (const TVector3 &direction) const
static TVector3 | getPerpendicularNormalization (const TVector3 &a, const TVector3 &b, const TVector3 &c)
static T | getTripleProduct (const TVector3< T > &a, const TVector3< T > &b, const TVector3< T > &c)

## Detailed Description

template<typename T>
class BALL::TVector3< T >

Generic Three-Dimensional Vector.

Definition at line 70 of file vector3.h.

## Constructor & Destructor Documentation

## TVector3() [1/8]

template<typename T>

BALL_INLINE BALL::TVector3< T >::TVector3 | ( |  | ) |

Default constructor. This method creates a new TVector3 object. The three components are initialized to (T)0.

Definition at line 534 of file vector3.h.

## TVector3() [2/8]

template<typename T>

BALL_INLINE BALL::TVector3< T >::TVector3 | ( | const T * | ptr | ) |

explicit

Array constructor. This constructor creates a TVector3 object from the first three elements pointed to by ptr.

Parameters

  ptr | the array to construct from

Exceptions

  NullPointer | if ptr == 0

Definition at line 543 of file vector3.h.

## TVector3() [3/8]

template<typename T>

BALL_INLINE BALL::TVector3< T >::TVector3 | ( | const T & | value | ) |

explicit

Scalar constructor. Create a new vector with all components set to the same value.

Parameters

  value | the value of all components

Definition at line 557 of file vector3.h.

## TVector3() [4/8]

template<typename T>
template<typename T2>

BALL::TVector3< T >::TVector3 | ( | const TVector3< T2 > & | vec | ) |

explicit

Explicit type conversion constructor between a vector of type T and T2

## TVector3() [5/8]

template<typename T>

BALL_INLINE BALL::TVector3< T >::TVector3 | ( | const T & | vx,
|  | const T & | vy,
|  | const T & | vz )

Detailed constructor. Create a new TVector3 object from three variables of type T.

Parameters

  vx | assigned to x
  vy | assigned to y
  vz | assigned to z

Definition at line 575 of file vector3.h.

## TVector3() [6/8]

template<typename T>

BALL_INLINE BALL::TVector3< T >::TVector3 | ( | const TVector3< T > & | vector | ) |

Copy constructor. Create a new TVector3 object from another.

Parameters

  vector | the TVector3 object to be copied

Definition at line 584 of file vector3.h.

## TVector3() [7/8]

template<typename T>

BALL_INLINE BALL::TVector3< T >::TVector3 | ( | const T & | r,
|  | const TAngle< T > & | phi,
|  | const TAngle< T > & | theta )

Spherical polar coordinate constructor. Create a TVector3 object and set its coordinates to the point described by the three spherical polar coordinates r (radius), phi (azimuth), and theta (co-latitude).

See also
  set(const T& r, const TAngle<T>& phi, const TAngle<T>& theta)

Parameters

  r | the radius
  phi | the azimuth
  theta | the co-latitude

Definition at line 593 of file vector3.h.

## ~TVector3()

template<typename T>

BALL_INLINE BALL::TVector3< T >::~TVector3 | ( |  | ) |

Destructor. Destructs the TVector3 object. As there are no dynamic data structures, nothing happens.

Definition at line 602 of file vector3.h.

## TVector3() [8/8]

template<typename T>
template<typename T2>

BALL_INLINE BALL::TVector3< T >::TVector3 | ( | const TVector3< T2 > & | vec | ) |

Definition at line 566 of file vector3.h.

## Member Function Documentation

## clear()

template<typename T>

BALL_INLINE void BALL::TVector3< T >::clear | ( |  | ) |

Clear method The values are set to 0.

Definition at line 608 of file vector3.h.

## dump()

template<typename T>

void BALL::TVector3< T >::dump | ( | std::ostream & | s = std::cout,
|  | Size | depth = 0 ) const

Internal state dump. Dump the current internal state of {*this} to the output ostream s with dumping depth depth .

Parameters

  s | - output stream where to output the internal state of {*this}
  depth | - the dumping depth

Definition at line 1069 of file vector3.h.

## get() [1/4]

template<typename T>

BALL_INLINE void BALL::TVector3< T >::get | ( | T & | r,
|  | TAngle< T > & | phi,
|  | TAngle< T > & | theta ) const

Assign to polar coordinates. Sets r, phi, and theta to the coordinates of the vector in spherical polar coordinates.

Parameters

  r | the radius (returned)
  phi | the azimuth (returned)
  theta | the co-latitude (returned)

Definition at line 731 of file vector3.h.

## get() [2/4]

template<typename T>

BALL_INLINE void BALL::TVector3< T >::get | ( | T & | x,
|  | T & | y,
|  | T & | z ) const

Assign to three variables of type T.

Parameters

  x | the x component
  y | the y component
  z | the z component

Definition at line 713 of file vector3.h.

## get() [3/4]

template<typename T>

BALL_INLINE void BALL::TVector3< T >::get | ( | T * | ptr | ) | const

Assign to an array. Sets the first three array elements pointed to by ptr to the values of the three vector components.

Parameters

  ptr | the array

Exceptions

  NullPointer | if ptr == 0

Definition at line 699 of file vector3.h.

## get() [4/4]

template<typename T>

void BALL::TVector3< T >::get | ( | TVector3< T > & | vector | ) | const

Assign to another Vector3. Assigns the vector components to another vector.

Parameters

  vector | the vector to be assigned to

## getAngle()

template<typename T>

BALL_INLINE TAngle< T > BALL::TVector3< T >::getAngle | ( | const TVector3< T > & | vector | ) | const

Return the enclosed angle of two vectors.

Exceptions

  Exception::DivisionByZero | if the product of the squared lengths of the two vectors equals (T)0

Definition at line 971 of file vector3.h.

## getDistance()

template<typename T>

BALL_INLINE T BALL::TVector3< T >::getDistance | ( | const TVector3< T > & | vector | ) | const

Return the distance to another vector.

Definition at line 949 of file vector3.h.

## getLength()

template<typename T>

BALL_INLINE T BALL::TVector3< T >::getLength | ( |  | ) | const

Return the length of the vector. The length of the vector is calculated as .

Returns
  T, the vector length

Definition at line 757 of file vector3.h.

## getOrthogonalProjection()

template<typename T>

BALL_INLINE TVector3< T > BALL::TVector3< T >::getOrthogonalProjection | ( | const TVector3< T > & | direction | ) | const

Return the orthogonal projection of this vector onto another.

Parameters

  direction | the vector to project onto

Definition at line 995 of file vector3.h.

## getPerpendicularNormalization()

template<typename T>

TVector3< T > BALL::TVector3< T >::getPerpendicularNormalization | ( | const TVector3< T > & | a,
|  | const TVector3< T > & | b,
|  | const TVector3< T > & | c )

static

Return the perpendicular normalization of the vector

Parameters

  a | 1st vector
  b | 2nd vector
  c | 3rd vector

Returns
  TVector3 the perpendicular normalization

Definition at line 1001 of file vector3.h.

## getSquareDistance()

template<typename T>

BALL_INLINE T BALL::TVector3< T >::getSquareDistance | ( | const TVector3< T > & | vector | ) | const

Return the squared distance to another vector.

Definition at line 960 of file vector3.h.

## getSquareLength()

template<typename T>

BALL_INLINE T BALL::TVector3< T >::getSquareLength | ( |  | ) | const

Return the squared length of the vector. This method avoids the square root needed in getLength, so this method is preferred if possible.

Returns
  T,

Definition at line 764 of file vector3.h.

## getTripleProduct()

template<typename T>

BALL_INLINE T BALL::TVector3< T >::getTripleProduct | ( | const TVector3< T > & | a,
|  | const TVector3< T > & | b,
|  | const TVector3< T > & | c )

static

Triple product of three vectors. Calculate the parallelepipedal product of three vectors.

Parameters

  a | first vector
  b | second vector
  v | third vector

Returns
  T the triple product

Definition at line 1015 of file vector3.h.

## getUnit()

template<typename T>

BALL_INLINE const TVector3< T > & BALL::TVector3< T >::getUnit | ( |  | ) |

static

Return a vector with all components 1.

Returns
  : TVector4(1, 1, 1, 1)

Definition at line 806 of file vector3.h.

## getZero()

template<typename T>

BALL_INLINE const TVector3< T > & BALL::TVector3< T >::getZero | ( |  | ) |

static

Return a vector with all components 0.

Definition at line 798 of file vector3.h.

## isOrthogonalTo()

template<typename T>

BALL_INLINE bool BALL::TVector3< T >::isOrthogonalTo | ( | const TVector3< T > & | vector | ) | const

Orthogonality predicate.

Definition at line 1049 of file vector3.h.

## isValid()

template<typename T>

BALL_INLINE bool BALL::TVector3< T >::isValid | ( |  | ) | const

Test if instance is valid. Always returns true.

Returns
  bool true

Definition at line 1056 of file vector3.h.

## isZero()

template<typename T>

BALL_INLINE bool BALL::TVector3< T >::isZero | ( |  | ) | const

Zero predicate. The function Maths::isZero is used to compare the values with zero. Maths::isZero

Definition at line 1063 of file vector3.h.

## negate()

template<typename T>

BALL_INLINE TVector3< T > & BALL::TVector3< T >::negate | ( |  | ) |

Negate the vector. Negate the three components of the vector

Returns
  T, a reference to {*this} vector

Definition at line 788 of file vector3.h.

## normalize()

template<typename T>

TVector3< T > & BALL::TVector3< T >::normalize | ( |  | ) |

Normalize the vector. The vector is scaled with its length: .

Returns
  T, a reference to the normalized vector

Exceptions

  DivisionByZero | if the length of the vector is 0

Definition at line 770 of file vector3.h.

## operator!=()

template<typename T>

BALL_INLINE bool BALL::TVector3< T >::operator!= | ( | const TVector3< T > & | vector | ) | const

Inequality operator. The function Maths::isEqual is used to compare the values. Maths::isEqual

Returns
  bool, true if the two vectors differ in at least one component, false otherwise

Definition at line 1042 of file vector3.h.

## operator%()

template<typename T>

TVector3< T > BALL::TVector3< T >::operator% | ( | const TVector3< T > & | vector | ) | const

Cross product. Return the cross product of this vector and vector.

Definition at line 934 of file vector3.h.

## operator%=()

template<typename T>

BALL_INLINE TVector3< T > & BALL::TVector3< T >::operator%= | ( | const TVector3< T > & | vector | ) |

Assign to the cross product. Assign the vector to its cross product with another vector.

Definition at line 941 of file vector3.h.

## operator*() [1/2]

template<typename T>

BALL_INLINE TVector3< T > BALL::TVector3< T >::operator* | ( | const T & | scalar | ) | const

Scalar product. Return TVector3(x * scalar, y * scalar, z * scalar).

Parameters

  scalar,the | scalar to multiply by

Returns
  TVector3 the scalar product of this vector and scalar

Definition at line 886 of file vector3.h.

## operator*() [2/2]

template<typename T>

T BALL::TVector3< T >::operator* | ( | const TVector3< T > & | vector | ) | const

Dot product. Return the dot product of this vector and vector.

## operator*=()

template<typename T>

BALL_INLINE TVector3< T > & BALL::TVector3< T >::operator*= | ( | const T & | scalar | ) |

Multiply by a scalar. Multiply all components of the vector by a scalar value.

Parameters

  scalar | the to multiply by

Returns
  TVector3&, {*this}

Definition at line 893 of file vector3.h.

## operator+() [1/2]

template<typename T>

BALL_INLINE const TVector3< T > & BALL::TVector3< T >::operator+ | ( |  | ) | const

Positive sign.

Definition at line 850 of file vector3.h.

## operator+() [2/2]

template<typename T>

TVector3 BALL::TVector3< T >::operator+ | ( | const TVector3< T > & | b | ) | const

Addition.

## operator+=()

template<typename T>

BALL_INLINE TVector3< T > & BALL::TVector3< T >::operator+= | ( | const TVector3< T > & | vector | ) |

Add a vector to this vector. Add the components of vector to this vector.

Parameters

  vector | the vector to add

Returns
  TVector3&, {*this}

Definition at line 864 of file vector3.h.

## operator-() [1/2]

template<typename T>

BALL_INLINE TVector3< T > BALL::TVector3< T >::operator- | ( |  | ) | const

Negative sign.

Definition at line 857 of file vector3.h.

## operator-() [2/2]

template<typename T>

TVector3 BALL::TVector3< T >::operator- | ( | const TVector3< T > & | b | ) | const

Subtraction.

## operator-=()

template<typename T>

BALL_INLINE TVector3< T > & BALL::TVector3< T >::operator-= | ( | const TVector3< T > & | vector | ) |

Subtract a vector from this vector.

Parameters

  vector | the vector to subtract

Returns
  TVector3&, {*this}

Definition at line 875 of file vector3.h.

## operator/()

template<typename T>

TVector3< T > BALL::TVector3< T >::operator/ | ( | const T & | lambda | ) | const

Fraction of a vector. Return TVector3(x / lambda, y / lambda, z / lambda).

Parameters

  lambda | the scalar value to divide by

Returns
  TVector3&

Exceptions

  Exception::DivisionByZero | if lambda == (T)0

Definition at line 903 of file vector3.h.

## operator/=()

template<typename T>

TVector3< T > & BALL::TVector3< T >::operator/= | ( | const T & | lambda | ) |

Divide a vector by a scalar.

Parameters

  lambda | the scalar value to divide by

Returns
  TVector3&, {*this}

Exceptions

  Exception::DivisionByZero | if lambda == (T)0

Definition at line 913 of file vector3.h.

## operator<()

template<typename T>

BALL_INLINE bool BALL::TVector3< T >::operator< | ( | const TVector3< T > & | vector | ) | const

Needed for MSVC.

Definition at line 1034 of file vector3.h.

## operator=() [1/3]

template<typename T>

BALL_INLINE TVector3< T > & BALL::TVector3< T >::operator= | ( | const T * | ptr | ) |

Array assignment operator. Assigns the first three elements of an array to the vector components.

Parameters

  ptr | the array

Exceptions

  NullPointer | if ptr == 0

Definition at line 663 of file vector3.h.

## operator=() [2/3]

template<typename T>

TVector3 & BALL::TVector3< T >::operator= | ( | const TVector3< T > & | v | ) |

Assignment operator. Assign the vector components from another vector.

Parameters

  v | the vector to assign from

## operator=() [3/3]

template<typename T>

BALL_INLINE TVector3< T > & BALL::TVector3< T >::operator= | ( | T | value | ) |

Assignment operator. Assign a constant value to all three vector components.

Parameters

  value | the constant to assign to x, y, z

Definition at line 690 of file vector3.h.

## operator==()

template<typename T>

BALL_INLINE bool BALL::TVector3< T >::operator== | ( | const TVector3< T > & | vector | ) | const

Equality operator. The function Maths::isEqual is used to compare the values. Maths::isEqual

Returns
  bool, true if all three vector components are equal, false otherwise

Definition at line 1027 of file vector3.h.

## operator[]() [1/2]

template<typename T>

BALL_INLINE T & BALL::TVector3< T >::operator[] | ( | Position | position | ) |

Mutable array-like access to the components.

Exceptions

  Exception::IndexOverflow | if index > 2

Definition at line 814 of file vector3.h.

## operator[]() [2/2]

template<typename T>

BALL_INLINE const T & BALL::TVector3< T >::operator[] | ( | Position | position | ) | const

Constant array-like access to the components.

Exceptions

  Exception::IndexOverflow | if index > 2

Definition at line 832 of file vector3.h.

## read()

template<typename T>

bool BALL::TVector3< T >::read | ( | PersistenceManager & | pm | ) |

Persistent stream reading.

Definition at line 1109 of file vector3.h.

## set() [1/5]

template<typename T>

BALL_INLINE void BALL::TVector3< T >::set | ( | const T & | r,
|  | const TAngle< T > & | phi,
|  | const TAngle< T > & | theta )

Assign from spherical polar coordinates. The radius describes the distance of the point from the origin.

  phi ranges from 0 to , theta ranges from 0 (north pole, positive z-axis) to (south pole, negative z-axis).

  Coordinates are calculated according to the following formulae:

Parameters

  r | the radius
  phi | the azimuth
  theta | the co-latitude

Definition at line 654 of file vector3.h.

## set() [2/5]

template<typename T>

BALL_INLINE void BALL::TVector3< T >::set | ( | const T & | value | ) |

Assign from a scalar. Assign value to the three vector components.

Parameters

  value | the new value of the components

Definition at line 627 of file vector3.h.

## set() [3/5]

template<typename T>

BALL_INLINE void BALL::TVector3< T >::set | ( | const T & | vx,
|  | const T & | vy,
|  | const T & | vz )

Assign the vector components.

Parameters

  vx | the new x component
  vy | the new y component
  vz | the new z component

Definition at line 636 of file vector3.h.

## set() [4/5]

template<typename T>

BALL_INLINE void BALL::TVector3< T >::set | ( | const T * | ptr | ) |

Assign from an array. Assign the three components x, y, and z from the first three elements of the array pointed to by ptr.

Parameters

  ptr | an array

Exceptions

  Nullpointer | if ptr == 0

Definition at line 615 of file vector3.h.

## set() [5/5]

template<typename T>

void BALL::TVector3< T >::set | ( | const TVector3< T > & | vector | ) |

Assign from another TVector3.

Parameters

  vector | the TVector3 object to assign from

## swap()

template<typename T>

BALL_INLINE void BALL::TVector3< T >::swap | ( | TVector3< T > & | vector | ) |

Swap the contents of two vectors.

Parameters

  vector | the vector to swap contents with

Definition at line 740 of file vector3.h.

## write()

template<typename T>

void BALL::TVector3< T >::write | ( | PersistenceManager & | pm | ) | const

Persistent stream writing.

Definition at line 1101 of file vector3.h.

## Member Data Documentation

## x

template<typename T>

T BALL::TVector3< T >::x

x component of the vector

Definition at line 489 of file vector3.h.

## y

template<typename T>

T BALL::TVector3< T >::y

y component of the vector

Definition at line 493 of file vector3.h.

## z

template<typename T>

T BALL::TVector3< T >::z

z component of the vector

Definition at line 497 of file vector3.h.