BALL::TVector3< T > Class Template Reference

#include <BALL/MATHS/vector3.h>

List of all members.

Public Member Functions

Constructors and Destructors
 TVector3 ()
 TVector3 (const T *ptr) throw (Exception::NullPointer)
 TVector3 (const T &value)
 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 TVector3operator+ () const
TVector3 operator- () const
TVector3 operator+ (const TVector3 &b) const
TVector3 operator- (const TVector3 &b) const
TVector3operator+= (const TVector3 &vector)
TVector3operator-= (const TVector3 &vector)
TVector3 operator* (const T &scalar) const
TVector3operator*= (const T &scalar)
TVector3 operator/ (const T &lambda) const throw (Exception::DivisionByZero)
TVector3operator/= (const T &lambda) throw (Exception::DivisionByZero)
operator* (const TVector3 &vector) const
TVector3 operator% (const TVector3 &vector) const
TVector3operator%= (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

Public Attributes

Vector components

For easier access, the three components of the vector are public members.

x
y
z

Private Member Functions

TAngle< T > getAngle_ (const T &a, const T &b) const

Assignment

void set (const T *ptr) throw (Exception::NullPointer)
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)
TVector3operator= (const TVector3 &v)
TVector3operator= (T value)
TVector3operator= (const T *ptr) throw (Exception::NullPointer)
void get (T *ptr) const throw (Exception::NullPointer)
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)
getLength () const
getSquareLength () const
TVector3normalize () throw (Exception::DivisionByZero)
TVector3negate ()
T & operator[] (Position position) throw (Exception::IndexOverflow)
const T & operator[] (Position position) const throw (Exception::IndexOverflow)
static const TVector3getZero ()
static const TVector3getUnit ()

Geometric properties

getDistance (const TVector3 &vector) const
getSquareDistance (const TVector3 &vector) const
TAngle< T > getAngle (const TVector3 &vector) const throw (Exception::DivisionByZero)
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.


Constructor & Destructor Documentation

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.

template<typename T>
BALL_INLINE BALL::TVector3< T >::TVector3 ( const T *  ptr) throw (Exception::NullPointer)

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

Parameters:
ptrthe array to construct from
Exceptions:
NullPointerif ptr == 0
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:
valuethe value of all components
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:
vxassigned to x
vyassigned to y
vzassigned to z
template<typename T>
BALL_INLINE BALL::TVector3< T >::TVector3 ( const TVector3< T > &  vector)

Copy constructor. Create a new TVector3 object from another.

Parameters:
vectorthe TVector3 object to be copied
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:
rthe radius
phithe azimuth
thetathe co-latitude
template<typename T >
BALL_INLINE BALL::TVector3< T >::~TVector3 ( )

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


Member Function Documentation

template<typename T >
BALL_INLINE void BALL::TVector3< T >::clear ( )

Clear method The values are set to 0.

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

References BALL_DUMP_DEPTH, BALL_DUMP_HEADER, BALL_DUMP_STREAM_PREFIX, and BALL_DUMP_STREAM_SUFFIX.

template<typename T>
BALL_INLINE void BALL::TVector3< T >::get ( T *  ptr) const throw (Exception::NullPointer)

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

Parameters:
ptrthe array
Exceptions:
NullPointerif ptr == 0
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:
xthe x component
ythe y component
zthe z component
template<typename T>
void BALL::TVector3< T >::get ( TVector3< T > &  vector) const

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

Parameters:
vectorthe vector to be assigned to
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:
rthe radius (returned)
phithe azimuth (returned)
thetathe co-latitude (returned)
template<typename T>
TAngle<T> BALL::TVector3< T >::getAngle ( const TVector3< T > &  vector) const throw (Exception::DivisionByZero)

Return the enclosed angle of two vectors.

Exceptions:
Exception::DivisionByZeroif the product of the squared lengths of the two vectors equals (T)0

Referenced by BALL::GetAngle().

template<typename T>
TAngle<T> BALL::TVector3< T >::getAngle_ ( const T &  a,
const T &  b 
) const [inline, private]
template<typename T>
T BALL::TVector3< T >::getDistance ( const TVector3< T > &  vector) const

Return the distance to another vector.

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 $\sqrt{x^2 + y^2 + z^2}$.

Returns:
T, the vector length

Referenced by BALL::TQuaternion< T >::fromAxisAngle(), BALL::TBox3< T >::setHeightVector(), and BALL::TBox3< T >::setRightVector().

template<typename T>
TVector3 BALL::TVector3< T >::getOrthogonalProjection ( const TVector3< T > &  direction) const

Return the orthogonal projection of this vector onto another.

Parameters:
directionthe vector to project onto
template<typename T>
static TVector3 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:
a1st vector
b2nd vector
c3rd vector
Returns:
TVector3 the perpendicular normalization
template<typename T>
T BALL::TVector3< T >::getSquareDistance ( const TVector3< T > &  vector) const

Return the squared distance to another vector.

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, $x^2 + y^2 + z^2$

Referenced by BALL::TVector3< float >::getAngle(), and BALL::GetAngle().

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:
afirst vector
bsecond vector
vthird vector
Returns:
T the triple product

References BALL::TVector3< T >::x, BALL::TVector3< T >::y, and BALL::TVector3< T >::z.

Referenced by BALL::GetDistance().

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)
template<typename T >
BALL_INLINE const TVector3< T > & BALL::TVector3< T >::getZero ( ) [static]

Return a vector with all components 0.

template<typename T>
bool BALL::TVector3< T >::isOrthogonalTo ( const TVector3< T > &  vector) const

Orthogonality predicate.

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

Test if instance is valid. Always returns true.

Returns:
bool true
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

References BALL::Maths::isZero().

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
template<typename T >
TVector3< T > & BALL::TVector3< T >::normalize ( ) throw (Exception::DivisionByZero)

Normalize the vector. The vector is scaled with its length: $\{x|y|z\} *= \sqrt{x^2 + y^2 + z^2}$.

Returns:
T, a reference to the normalized vector
Exceptions:
DivisionByZeroif the length of the vector is 0

References BALL::Maths::isZero().

Referenced by BALL::TBox3< T >::getDiagonalVector(), BALL::GetIntersection(), and BALL::VIEW::Camera::moveForward().

template<typename T>
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
template<typename T>
TVector3 BALL::TVector3< T >::operator% ( const TVector3< T > &  vector) const

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

template<typename T>
TVector3& BALL::TVector3< T >::operator%= ( const TVector3< T > &  vector)

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

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

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

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,thescalar to multiply by
Returns:
TVector3 the scalar product of this vector and scalar
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:
scalarthe to multiply by
Returns:
TVector3&, {*this}
template<typename T >
BALL_INLINE const TVector3< T > & BALL::TVector3< T >::operator+ ( ) const

Positive sign.

template<typename T>
TVector3 BALL::TVector3< T >::operator+ ( const TVector3< T > &  b) const
template<typename T>
TVector3& BALL::TVector3< T >::operator+= ( const TVector3< T > &  vector)

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

Parameters:
vectorthe vector to add
Returns:
TVector3&, {*this}
template<typename T>
TVector3 BALL::TVector3< T >::operator- ( const TVector3< T > &  b) const
template<typename T >
BALL_INLINE TVector3< T > BALL::TVector3< T >::operator- ( ) const

Negative sign.

template<typename T>
TVector3& BALL::TVector3< T >::operator-= ( const TVector3< T > &  vector)

Subtract a vector from this vector.

Parameters:
vectorthe vector to subtract
Returns:
TVector3&, {*this}
template<typename T>
TVector3< T > BALL::TVector3< T >::operator/ ( const T &  lambda) const throw (Exception::DivisionByZero)

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

Parameters:
lambdathe scalar value to divide by
Returns:
TVector3&
Exceptions:
Exception::DivisionByZeroif lambda == (T)0
template<typename T>
TVector3< T > & BALL::TVector3< T >::operator/= ( const T &  lambda) throw (Exception::DivisionByZero)

Divide a vector by a scalar.

Parameters:
lambdathe scalar value to divide by
Returns:
TVector3&, {*this}
Exceptions:
Exception::DivisionByZeroif lambda == (T)0
template<typename T>
bool BALL::TVector3< T >::operator< ( const TVector3< T > &  vector) const

Needed for MSVC.

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

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

Parameters:
valuethe constant to assign to x, y, z
template<typename T>
BALL_INLINE TVector3< T > & BALL::TVector3< T >::operator= ( const T *  ptr) throw (Exception::NullPointer)

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

Parameters:
ptrthe array
Exceptions:
NullPointerif ptr == 0
template<typename T>
TVector3& BALL::TVector3< T >::operator= ( const TVector3< T > &  v)

Assignment operator. Assign the vector components from another vector.

Parameters:
vthe vector to assign from
template<typename T>
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
template<typename T >
BALL_INLINE T & BALL::TVector3< T >::operator[] ( Position  position) throw (Exception::IndexOverflow)

Mutable array-like access to the components.

Exceptions:
Exception::IndexOverflowif index > 2
template<typename T >
BALL_INLINE const T & BALL::TVector3< T >::operator[] ( Position  position) const throw (Exception::IndexOverflow)

Constant array-like access to the components.

Exceptions:
Exception::IndexOverflowif index > 2
template<typename T >
bool BALL::TVector3< T >::read ( PersistenceManager pm)

Persistent stream reading.

References BALL::PersistenceManager::readPrimitive().

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

Assign the vector components.

Parameters:
vxthe new x component
vythe new y component
vzthe new z component
template<typename T>
void BALL::TVector3< T >::set ( const TVector3< T > &  vector)

Assign from another TVector3.

Parameters:
vectorthe TVector3 object to assign from
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 $2 \pi$, theta ranges from 0 (north pole, positive z-axis) to $\pi$ (south pole, negative z-axis).
Coordinates are calculated according to the following formulae:

\[ x = r \sin \theta \cos \phi \]

\[ y = r \sin \theta \sin \phi \]

\[ z = r \cos \theta \]

Parameters:
rthe radius
phithe azimuth
thetathe co-latitude
template<typename T>
BALL_INLINE void BALL::TVector3< T >::set ( const T *  ptr) throw (Exception::NullPointer)

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:
ptran array
Exceptions:
Nullpointerif ptr == 0

Referenced by BALL::TSimpleBox3< T >::get(), BALL::HashGrid3< Item >::get(), BALL::TFFT3D< ComplexTraits >::getGridCoordinates(), BALL::GetIntersection(), and BALL::operator<<().

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:
valuethe new value of the components
template<typename T>
void BALL::TVector3< T >::swap ( TVector3< T > &  vector)

Swap the contents of two vectors.

Parameters:
vectorthe vector to swap contents with
template<typename T >
void BALL::TVector3< T >::write ( PersistenceManager pm) const

Persistent stream writing.

References BALL::PersistenceManager::writePrimitive().


Member Data Documentation