Main Page | Modules | Namespace List | Class Hierarchy | Class List | Namespace Members | Class Members

TVector3< T > Class Template Reference
[Three-dimensional vector.]

Generic Three-Dimensional Vector. More...

#include <vector3.h>

List of all members.

Assignment

void set (const T *ptr) throw (Exception::NullPointer)
 Assign from an array.
void set (const T &value) throw ()
 Assign from a scalar.
void set (const T &vx, const T &vy, const T &vz) throw ()
 Assign the vector components.
void set (const TVector3 &vector) throw ()
 Assign from another TVector3.
void set (const T &r, const TAngle< T > &phi, const TAngle< T > &theta) throw ()
 Assign from spherical polar coordinates.
TVector3operator= (const TVector3 &v) throw ()
 Assignment operator.
TVector3operator= (T value) throw ()
 Assignment operator.
TVector3operator= (const T *ptr) throw (Exception::NullPointer)
 Array assignment operator.
void get (T *ptr) const throw (Exception::NullPointer)
 Assign to an array.
void get (T &x, T &y, T &z) const throw ()
 Assign to three variables of type T.
void get (TVector3 &vector) const throw ()
 Assign to another Vector3.
void get (T &r, TAngle< T > &phi, TAngle< T > &theta) const throw ()
 Assign to polar coordinates.
void swap (TVector3 &vector) throw ()
 Swap the contents of two vectors.
getLength () const throw ()
 Return the length of the vector.
getSquareLength () const throw ()
 Return the squared length of the vector.
TVector3normalize () throw (Exception::DivisionByZero)
 Normalize the vector.
TVector3negate () throw ()
 Negate the vector.
T & operator[] (Position position) throw (Exception::IndexOverflow)
 Mutable array-like access to the components.
const T & operator[] (Position position) const throw (Exception::IndexOverflow)
 Constant array-like access to the components.
const TVector3getZero () throw ()
 Return a vector with all components 0.
const TVector3getUnit () throw ()
 Return a vector with all components 1.

Geometric properties

getDistance (const TVector3 &vector) const throw ()
 Return the distance to another vector.
getSquareDistance (const TVector3 &vector) const throw ()
 Return the squared distance to another vector.
TAngle< T > getAngle (const TVector3 &vector) const throw (Exception::DivisionByZero)
 Return the enclosed angle of two vectors.
TVector3 getOrthogonalProjection (const TVector3 &direction) const throw ()
 Return the orthogonal projection of this vector onto another.
TVector3 getPerpendicularNormalization (const TVector3 &a, const TVector3 &b, const TVector3 &c) throw ()
 Return the perpendicular normalization of the vector.
getTripleProduct (const TVector3< T > &a, const TVector3< T > &b, const TVector3< T > &c) throw ()
 Triple product of three vectors.

Public Member Functions

Constructors and Destructors
 TVector3 () throw ()
 Default constructor.
 TVector3 (const T *ptr) throw (Exception::NullPointer)
 Array constructor.
 TVector3 (const T &value) throw ()
 Scalar constructor.
 TVector3 (const T &vx, const T &vy, const T &vz) throw ()
 Detailed constructor.
 TVector3 (const TVector3 &vector) throw ()
 Copy constructor.
 TVector3 (const T &r, const TAngle< T > &phi, const TAngle< T > &theta) throw ()
 Spherical polar coordinate constructor.
 ~TVector3 () throw ()
 Destructor.
void clear () throw ()
 Clear method The values are set to 0.
Arithmetic operators
const TVector3operator+ () const throw ()
 Positive sign.
TVector3 operator- () const throw ()
 Negative sign.
TVector3 operator+ (const TVector3 &b) const throw ()
 Addition.
TVector3 operator- (const TVector3 &b) const throw ()
 Subtraction.
TVector3operator+= (const TVector3 &vector) throw ()
 Add a vector to this vector.
TVector3operator-= (const TVector3 &vector) throw ()
 Subtract a vector from this vector.
TVector3 operator * (const T &scalar) const throw ()
 Scalar product.
TVector3operator *= (const T &scalar) throw ()
 Multiply by a scalar.
TVector3 operator/ (const T &lambda) const throw (Exception::DivisionByZero)
 Fraction of a vector.
TVector3operator/= (const T &lambda) throw (Exception::DivisionByZero)
 Divide a vector by a scalar.
operator * (const TVector3 &vector) const throw ()
 Dot product.
TVector3 operator% (const TVector3 &vector) const throw ()
 Cross product.
TVector3operator%= (const TVector3 &vector) throw ()
 Assign to the cross product.
Predicates
bool operator== (const TVector3 &vector) const throw ()
 Equality operator.
bool operator!= (const TVector3 &vector) const throw ()
 Inequality operator.
bool operator< (const TVector3 &vector) const throw ()
 Needed for MSVC.
bool isZero () const throw ()
 Zero predicate.
bool isOrthogonalTo (const TVector3 &vector) const throw ()
 Orthogonality predicate.
Storable Interface
void write (PersistenceManager &pm) const throw ()
 Persistent stream writing.
bool read (PersistenceManager &pm) throw ()
 Persistent stream reading.
Debugging and Diagnostics
void dump (std::ostream &s=std::cout, Size depth=0) const throw ()
 Internal state dump.
bool isValid () const throw ()
 Test if instance is valid.

Public Attributes

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

x
 x component of the vector
y
 y component of the vector
z
 z component of the vector


Detailed Description

template<typename T>
class TVector3< T >

Generic Three-Dimensional Vector.


Constructor & Destructor Documentation

template<typename T>
TVector3< T >::TVector3  )  throw ()
 

Default constructor.

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

template<typename T>
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:
ptr the array to construct from
Exceptions:
NullPointer if ptr == 0

template<typename T>
TVector3< T >::TVector3 const T &  value  )  throw () [explicit]
 

Scalar constructor.

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

Parameters:
value the value of all components

template<typename T>
TVector3< T >::TVector3 const T &  vx,
const T &  vy,
const T &  vz
throw ()
 

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

template<typename T>
TVector3< T >::TVector3 const TVector3< T > &  vector  )  throw ()
 

Copy constructor.

Create a new TVector3 object from another.

Parameters:
vector the TVector3 object to be copied

template<typename T>
TVector3< T >::TVector3 const T &  r,
const TAngle< T > &  phi,
const TAngle< T > &  theta
throw ()
 

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

template<typename T>
TVector3< T >::~TVector3  )  throw ()
 

Destructor.

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


Member Function Documentation

template<typename T>
void TVector3< T >::clear  )  throw ()
 

Clear method The values are set to 0.

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

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

template<typename T>
void TVector3< T >::get T &  r,
TAngle< T > &  phi,
TAngle< T > &  theta
const throw ()
 

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)

template<typename T>
void TVector3< T >::get TVector3< T > &  vector  )  const throw ()
 

Assign to another Vector3.

Assigns the vector components to another vector.

Parameters:
vector the vector to be assigned to

template<typename T>
void TVector3< T >::get T &  x,
T &  y,
T &  z
const throw ()
 

Assign to three variables of type T.

Parameters:
x the x component
y the y component
z the z component

template<typename T>
void 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:
ptr the array
Exceptions:
NullPointer if ptr == 0

template<typename T>
TAngle< T > TVector3< T >::getAngle const TVector3< T > &  vector  )  const throw (Exception::DivisionByZero)
 

Return the enclosed angle of two vectors.

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

template<typename T>
T TVector3< T >::getDistance const TVector3< T > &  vector  )  const throw ()
 

Return the distance to another vector.

template<typename T>
T TVector3< T >::getLength  )  const throw ()
 

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

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

Return the orthogonal projection of this vector onto another.

Parameters:
direction the vector to project onto

template<typename T>
TVector3< T > TVector3< T >::getPerpendicularNormalization const TVector3< T > &  a,
const TVector3< T > &  b,
const TVector3< T > &  c
throw () [static]
 

Return the perpendicular normalization of the vector.

Parameters:
a 1st vector
b 2nd vector
c 3rd vector
Returns:
TVector3 the perpendicular normalization

template<typename T>
T TVector3< T >::getSquareDistance const TVector3< T > &  vector  )  const throw ()
 

Return the squared distance to another vector.

template<typename T>
T TVector3< T >::getSquareLength  )  const throw ()
 

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$

template<typename T>
T TVector3< T >::getTripleProduct const TVector3< T > &  a,
const TVector3< T > &  b,
const TVector3< T > &  c
throw () [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

template<typename T>
const TVector3< T > & TVector3< T >::getUnit  )  throw () [static]
 

Return a vector with all components 1.

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

template<typename T>
const TVector3< T > & TVector3< T >::getZero  )  throw () [static]
 

Return a vector with all components 0.

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

Orthogonality predicate.

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

Test if instance is valid.

Always returns true.

Returns:
bool true

template<typename T>
bool TVector3< T >::isZero  )  const throw ()
 

Zero predicate.

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

template<typename T>
TVector3< T > & TVector3< T >::negate  )  throw ()
 

Negate the vector.

Negate the three components of the vector

Returns:
T, a reference to {*this} vector

template<typename T>
TVector3< T > & 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:
DivisionByZero if the length of the vector is 0

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

Dot product.

Return the dot product of this vector and vector.

template<typename T>
TVector3< T > TVector3< T >::operator * const T &  scalar  )  const throw ()
 

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

template<typename T>
TVector3< T > & TVector3< T >::operator *= const T &  scalar  )  throw ()
 

Multiply by a scalar.

Multiply all components of the vector by a scalar value.

Parameters:
scalar the to multiply by
Returns:
TVector3&, {*this}

template<typename T>
bool TVector3< T >::operator!= const TVector3< T > &  vector  )  const throw ()
 

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

Cross product.

Return the cross product of this vector and vector.

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

Assign to the cross product.

Assign the vector to its cross product with another vector.

template<typename T>
TVector3< T > TVector3< T >::operator+ const TVector3< T > &  b  )  const throw ()
 

Addition.

template<typename T>
const TVector3< T > & TVector3< T >::operator+  )  const throw ()
 

Positive sign.

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

Add a vector to this vector.

Add the components of vector to this vector.

Parameters:
vector the vector to add
Returns:
TVector3&, {*this}

template<typename T>
TVector3< T > TVector3< T >::operator- const TVector3< T > &  b  )  const throw ()
 

Subtraction.

template<typename T>
TVector3< T > TVector3< T >::operator-  )  const throw ()
 

Negative sign.

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

Subtract a vector from this vector.

Parameters:
vector the vector to subtract
Returns:
TVector3&, {*this}

template<typename T>
TVector3< T > TVector3< T >::operator/ const T &  lambda  )  const throw (Exception::DivisionByZero)
 

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

template<typename T>
TVector3< T > & TVector3< T >::operator/= const T &  lambda  )  throw (Exception::DivisionByZero)
 

Divide a vector by a scalar.

Parameters:
lambda the scalar value to divide by
Returns:
TVector3&, {*this}
Exceptions:
Exception::DivisionByZero if lambda == (T)0

template<typename T>
TVector3< T > & 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:
ptr the array
Exceptions:
NullPointer if ptr == 0

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

Assignment operator.

Assign a constant value to all three vector components.

Parameters:
value the constant to assign to x, y, z

template<typename T>
TVector3< T > & TVector3< T >::operator= const TVector3< T > &  v  )  throw ()
 

Assignment operator.

Assign the vector components from another vector.

Parameters:
v the vector to assign from

template<typename T>
bool TVector3< T >::operator== const TVector3< T > &  vector  )  const throw ()
 

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>
const T & TVector3< T >::operator[] Position  position  )  const throw (Exception::IndexOverflow)
 

Constant array-like access to the components.

Exceptions:
Exception::IndexOverflow if index > 2

template<typename T>
T & TVector3< T >::operator[] Position  position  )  throw (Exception::IndexOverflow)
 

Mutable array-like access to the components.

Exceptions:
Exception::IndexOverflow if index > 2

template<typename T>
void TVector3< T >::set const T &  r,
const TAngle< T > &  phi,
const TAngle< T > &  theta
throw ()
 

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:
r the radius
phi the azimuth
theta the co-latitude

template<typename T>
void TVector3< T >::set const TVector3< T > &  vector  )  throw ()
 

Assign from another TVector3.

Parameters:
vector the TVector3 object to assign from

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

Assign the vector components.

Parameters:
vx the new x component
vy the new y component
vz the new z component

template<typename T>
void TVector3< T >::set const T &  value  )  throw ()
 

Assign from a scalar.

Assign value to the three vector components.

Parameters:
value the new value of the components

template<typename T>
void 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:
ptr an array
Exceptions:
Nullpointer if ptr == 0

template<typename T>
void TVector3< T >::swap TVector3< T > &  vector  )  throw ()
 

Swap the contents of two vectors.

Parameters:
vector the vector to swap contents with