VectorTemplate< N, T > Class Template Reference

#include <VectorTemplate.h>

List of all members.

Public Member Functions

 VectorTemplate (void)
 VectorTemplate (const VectorTemplate< N, T > &v)
 ~VectorTemplate (void)
VectorTemplate< N, T > & operator= (const VectorTemplate< N, T > &v)
bool operator== (const VectorTemplate< N, T > &v) const
T & operator[] (unsigned int i)
const T & operator[] (unsigned int i) const
VectorTemplate< N, T > & operator+= (const VectorTemplate< N, T > &v)
VectorTemplate< N, T > & operator-= (const VectorTemplate< N, T > &v)
VectorTemplate< N, T > & operator *= (T s)
VectorTemplate< N, T > & operator/= (T s)
VectorTemplate< N, T > operator- ()
VectorTemplate< N, T > operator+ (const VectorTemplate< N, T > &v) const
VectorTemplate< N, T > operator- (const VectorTemplate< N, T > &v) const
VectorTemplate< N, T > operator * (T s) const
VectorTemplate< N, T > operator/ (T s) const
double dot (const VectorTemplate< N, T > &v) const
double length () const
VectorTemplate< N, T > & normalize ()
double calculateAngleWith (const VectorTemplate< N, T > &v)
double calculateSignedAngleWith (const VectorTemplate< N, T > &v)
VectorTemplate< N, T > cross (const VectorTemplate< N, T > &v)


Detailed Description

template<unsigned int N, class T>
class VectorTemplate< N, T >

This class defines a template for a multi-dimensional vector structure. In order to use it, the dimension and the type of the elements must be given. Some common cases are already provided as the defined types Vector2i, Vector2f, Vector2d, Vector3i, Vector3f, and Vector3d.

The methods in this template class do not provide boundary check. The user must make sure that indices are inside the bounds of the specified vector dimension when using it. This provides better performance and assumes that this kind of logic mistake should be rare.

This template was based on the example given to the students by TAs Torin Taerum and Fabricio Anastacio in the CPSC453 Introduction to Computer Graphics course at the University of Calgary, Canada, in the Fall 2006 term.

Author:
Fabricio Anastacio - fabriciocfa@yahoo.com
Since:
June 27, 2007


Constructor & Destructor Documentation

template<unsigned int N, class T>
VectorTemplate< N, T >::VectorTemplate ( void   )  [inline]

Constructs a vector of the given dimension and type initialized with 0.

template<unsigned int N, class T>
VectorTemplate< N, T >::VectorTemplate ( const VectorTemplate< N, T > &  v  )  [inline]

Constructor for copying a vector of the given dimension and type.

Parameters:
v the vector to be copied to this one.

template<unsigned int N, class T>
VectorTemplate< N, T >::~VectorTemplate ( void   )  [inline]

Destroys this vector.


Member Function Documentation

template<unsigned int N, class T>
VectorTemplate<N, T>& VectorTemplate< N, T >::operator= ( const VectorTemplate< N, T > &  v  )  [inline]

Vector assignment.

the vector to be assigned to this one.

template<unsigned int N, class T>
bool VectorTemplate< N, T >::operator== ( const VectorTemplate< N, T > &  v  )  const [inline]

Vector equal comparison.

the vector to be assigned to this one.

template<unsigned int N, class T>
T& VectorTemplate< N, T >::operator[] ( unsigned int  i  )  [inline]

Array-like access to the elements.

Parameters:
i the index of the element in the data array.

template<unsigned int N, class T>
const T& VectorTemplate< N, T >::operator[] ( unsigned int  i  )  const [inline]

Array-like access to the elements (const version).

Parameters:
i the index of the element in the data array.

template<unsigned int N, class T>
VectorTemplate<N, T>& VectorTemplate< N, T >::operator+= ( const VectorTemplate< N, T > &  v  )  [inline]

Adds the vector v to the current vector.

Parameters:
v the vector to be added to this one.

template<unsigned int N, class T>
VectorTemplate<N, T>& VectorTemplate< N, T >::operator-= ( const VectorTemplate< N, T > &  v  )  [inline]

Subtracts the vector v to the current vector.

Parameters:
v the vector to be subtracted from this one.

template<unsigned int N, class T>
VectorTemplate<N, T>& VectorTemplate< N, T >::operator *= ( s  )  [inline]

Multiplies the value of the scalar s by the current vector.

Parameters:
s the scalar value to be multipled by this vector.

template<unsigned int N, class T>
VectorTemplate<N, T>& VectorTemplate< N, T >::operator/= ( s  )  [inline]

Divides the value of the scalar s by the current vector.

Parameters:
s the scalar value to be divided by this vector.

template<unsigned int N, class T>
VectorTemplate<N, T> VectorTemplate< N, T >::operator- (  )  [inline]

Negates this vector.

template<unsigned int N, class T>
VectorTemplate<N, T> VectorTemplate< N, T >::operator+ ( const VectorTemplate< N, T > &  v  )  const [inline]

Returns the result of adding the vector v to the current vector.

Parameters:
v the vector to be added to this one.
Returns:
the resulting of adding this vector to v.

template<unsigned int N, class T>
VectorTemplate<N, T> VectorTemplate< N, T >::operator- ( const VectorTemplate< N, T > &  v  )  const [inline]

Returns the result of subtracting the vector v from the current vector.

Parameters:
v the vector to be added to this one.
Returns:
the result of subtracting this vector from v.

template<unsigned int N, class T>
VectorTemplate<N, T> VectorTemplate< N, T >::operator * ( s  )  const [inline]

Returns the result of multiplying this vector by the scalar s.

Parameters:
s the scalar value to be multiplied by this vector.
Returns:
the result of multiplying this vector by s.

template<unsigned int N, class T>
VectorTemplate<N, T> VectorTemplate< N, T >::operator/ ( s  )  const [inline]

Returns the result of dividing this vector by the scalar s.

Parameters:
s the scalar value to be divided by this vector.
Returns:
the result of dividing this vector by s.

template<unsigned int N, class T>
double VectorTemplate< N, T >::dot ( const VectorTemplate< N, T > &  v  )  const [inline]

Returns the dot product between this vector and v.

Parameters:
v the vector to be dot-producted with this one.
Returns:
the dot product between this vector and v.

template<unsigned int N, class T>
double VectorTemplate< N, T >::length (  )  const [inline]

Returns the length (a.k.a., norm, magnitude) of this vector.

Returns:
the length of this vector.

template<unsigned int N, class T>
VectorTemplate<N, T>& VectorTemplate< N, T >::normalize (  )  [inline]

Normalizes this vector.

template<unsigned int N, class T>
double VectorTemplate< N, T >::calculateAngleWith ( const VectorTemplate< N, T > &  v  )  [inline]

Calculates the angle in radians between this vector and v. This operation is only implemented for two dimensional vectors. If they have different dimensions a std::logic_error exception is thrown.

Parameters:
v the vector whose angle with this one will be calculated.
Returns:
the angle between this vector and the given one.
Exceptions:
std::logic_error exception if the vectors are not 2D.

template<unsigned int N, class T>
double VectorTemplate< N, T >::calculateSignedAngleWith ( const VectorTemplate< N, T > &  v  )  [inline]

Calculates the signed angle in radians between this vector and v. In other words, it returns the angle that this vector must be rotated by so that it points in the same direction as v. The returned angle is inside the (-PI, PI) interval. This operation is only implemented for two dimensional vectors. If they have different dimensions a std::logic_error exception is thrown.

Parameters:
v the vector whose signed angle with this one will be calculated.
Returns:
the signed angle between this vector and the given one.
Exceptions:
std::logic_error exception if the vectors are not 2D.

template<unsigned int N, class T>
VectorTemplate<N, T> VectorTemplate< N, T >::cross ( const VectorTemplate< N, T > &  v  )  [inline]

Returns a vector with the cross product of this vector with v. This operation only makes sense if the involved vectors have three dimensions. If they have different dimensions a std::logic_error exception is thrown.

Parameters:
v the vector to be cross-producted with this one (this X v).
Returns:
the vector resulting from the cross product of this vector and v.
Exceptions:
std::logic_error exception if the vectors are not 3D.


The documentation for this class was generated from the following file:
Generated on Fri Dec 21 17:43:50 2007 for LargeDisplayFramework by  doxygen 1.5.2