#include <VectorTemplate.h>
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) |
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.
VectorTemplate< N, T >::VectorTemplate | ( | void | ) | [inline] |
Constructs a vector of the given dimension and type initialized with 0.
VectorTemplate< N, T >::VectorTemplate | ( | const VectorTemplate< N, T > & | v | ) | [inline] |
Constructor for copying a vector of the given dimension and type.
v | the vector to be copied to this one. |
VectorTemplate< N, T >::~VectorTemplate | ( | void | ) | [inline] |
Destroys this vector.
VectorTemplate<N, T>& VectorTemplate< N, T >::operator= | ( | const VectorTemplate< N, T > & | v | ) | [inline] |
Vector assignment.
the vector to be assigned to this one.
bool VectorTemplate< N, T >::operator== | ( | const VectorTemplate< N, T > & | v | ) | const [inline] |
Vector equal comparison.
the vector to be assigned to this one.
T& VectorTemplate< N, T >::operator[] | ( | unsigned int | i | ) | [inline] |
Array-like access to the elements.
i | the index of the element in the data array. |
const T& VectorTemplate< N, T >::operator[] | ( | unsigned int | i | ) | const [inline] |
Array-like access to the elements (const version).
i | the index of the element in the data array. |
VectorTemplate<N, T>& VectorTemplate< N, T >::operator+= | ( | const VectorTemplate< N, T > & | v | ) | [inline] |
Adds the vector v to the current vector.
v | the vector to be added to this one. |
VectorTemplate<N, T>& VectorTemplate< N, T >::operator-= | ( | const VectorTemplate< N, T > & | v | ) | [inline] |
Subtracts the vector v to the current vector.
v | the vector to be subtracted from this one. |
VectorTemplate<N, T>& VectorTemplate< N, T >::operator *= | ( | T | s | ) | [inline] |
Multiplies the value of the scalar s by the current vector.
s | the scalar value to be multipled by this vector. |
VectorTemplate<N, T>& VectorTemplate< N, T >::operator/= | ( | T | s | ) | [inline] |
Divides the value of the scalar s by the current vector.
s | the scalar value to be divided by this vector. |
VectorTemplate<N, T> VectorTemplate< N, T >::operator- | ( | ) | [inline] |
Negates this vector.
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.
v | the vector to be added to this one. |
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.
v | the vector to be added to this one. |
VectorTemplate<N, T> VectorTemplate< N, T >::operator * | ( | T | s | ) | const [inline] |
Returns the result of multiplying this vector by the scalar s.
s | the scalar value to be multiplied by this vector. |
VectorTemplate<N, T> VectorTemplate< N, T >::operator/ | ( | T | s | ) | const [inline] |
Returns the result of dividing this vector by the scalar s.
s | the scalar value to be divided by this vector. |
double VectorTemplate< N, T >::dot | ( | const VectorTemplate< N, T > & | v | ) | const [inline] |
Returns the dot product between this vector and v.
v | the vector to be dot-producted with this one. |
double VectorTemplate< N, T >::length | ( | ) | const [inline] |
Returns the length (a.k.a., norm, magnitude) of this vector.
VectorTemplate<N, T>& VectorTemplate< N, T >::normalize | ( | ) | [inline] |
Normalizes this vector.
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.
v | the vector whose angle with this one will be calculated. |
std::logic_error | exception if the vectors are not 2D. |
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.
v | the vector whose signed angle with this one will be calculated. |
std::logic_error | exception if the vectors are not 2D. |
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.
v | the vector to be cross-producted with this one (this X v). |
std::logic_error | exception if the vectors are not 3D. |