compile-time (static) vector of size N More...
Public Member Functions | |
Vector () | |
default constructor | |
Vector (unsigned n) | |
construct with n elems | |
Vector (T const *v) | |
construct from an array | |
T & | operator() (unsigned i) |
mutable index operator | |
T const & | operator() (unsigned i) const |
immutable index operator | |
Vector< T, N > & | operator+= (Vector< T, N > const &b) |
add a vector to this vector | |
Vector< T, N > | operator+ (Vector< T, N > const &b) const |
add two vectors | |
Vector< T, N > & | operator-= (Vector< T, N > const &b) |
subtract a vector from this vector | |
Vector< T, N > | operator- (Vector< T, N > const &b) const |
subtract two vectors | |
Vector< T, N > | operator* (T const &s) const |
multiply a vector times a scalar | |
Vector< T, N > | operator/ (T const &s) const |
divide a vector by a scalar | |
T | operator* (Vector< T, N > const &b) const |
vector dot product | |
T | getLength () const |
get the vector magnitude | |
Vector< T, N > | normalize () const |
divide the vector by its magnitude | |
void | zero () |
zero the vector |
compile-time (static) vector of size N
This class endows Array<T,N> with the standard mathematical properties of a linear algebra vector. The vector is templated on scalar type so that math can be performed for a variety of (meaningful) scalar types.
Definition at line 29 of file mthVector.h.
mth::Vector< T, N >::Vector | ( | unsigned | n | ) | [inline] |
construct with n elems
A dummy constructor Vector(n) is provided so that dynamic and static vectors can be used interchangebly
Definition at line 37 of file mthVector.h.
{(void)n;}
T& mth::Vector< T, N >::operator() | ( | unsigned | i | ) | [inline] |
mutable index operator
An index operator (i) is provided so that mth::Vector and mth::Matrix share a common index operator
Definition at line 47 of file mthVector.h.
{return (*this)[i];}
T mth::Vector< T, N >::operator* | ( | Vector< T, N > const & | b | ) | const [inline] |
vector dot product
we chose the default vector-vector multiplication operator to be the dot product. so far this seems to have been a good choice
Definition at line 104 of file mthVector.h.
{ T r = (T)0.0; for (unsigned i=0; i < N; ++i) r += (*this)[i] * b[i]; return r; }
Vector<T,N> mth::Vector< T, N >::operator* | ( | T const & | s | ) | const [inline] |
multiply a vector times a scalar
currently there is no scalar times vector operator, so do be sure to put scalar on the right hand side
Definition at line 84 of file mthVector.h.
{ Vector<T,N> r; for (unsigned i=0; i < N; ++i) r[i] = (*this)[i] * s; return r; }
Vector<T,N> mth::Vector< T, N >::operator/ | ( | T const & | s | ) | const [inline] |
divide a vector by a scalar
equivalent to scaling by 1/s
Definition at line 93 of file mthVector.h.
{ Vector<T,N> r; for (unsigned i=0; i < N; ++i) r[i] = (*this)[i] / s; return r; }