Main Page | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

Vector< n > Class Template Reference

Generic n-dimensional vector. More...

#include <geometry.hh>

Collaboration diagram for Vector< n >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Vector ()
 Default constructor initializes to nothing.

 Vector (const double data[n])
 Constructor for initializing to given value.

double getLength () const
 Gets the length of the vector.

bool isNormalized () const
 Determines if the vector is normalized.

void normalize ()
 Normalizes this vector, adjusting it to unit length.

void translateGL () const
 Translates the current GL context by this vector.

double operator[] (unsigned int i) const
 Gets a component of this vector.

const Vector< n > & operator *= (double d)
 Multiplies this vector by a scalar.

const Vector< n > & operator/= (double d)
 Divides this vector by a scalar.

const Vector< n > & operator+= (const Vector< n > &v)
 Adds a vector to this one.

const Vector< n > & operator-= (const Vector< n > &v)
 Subtracts a vector from this one.

Vector< n > operator- () const
 Returns this vector's inverse.

const Matrix< n+1, 1 > & getMatrix () const
 Returns the matrix used to represent this vector.


Static Public Attributes

const double NORMAL_EPSILON = 1e-6
 The epsilon to use for determining if a vector is normalized or not.


Private Attributes

Matrix< n+1, 1 > data
 The matrix representing this point.


Friends

template<unsigned int n2> Vector< n2 > operator- (const Point< n2 > &a, const Point< n2 > &b)
 Subtracts two points to get a vector.


Related Functions

(Note that these are not member functions.)

Vector< n > operator * (const Vector< n > &a, double b)
 Multiply a vector by a scalar.

Vector< n > operator/ (const Vector< n > &a, double b)
 Divides a vector by a scalar.

Vector< n > operator * (double b, const Vector< n > &a)
 Multiplies a scalar by a vector (commutative).

Vector< n > operator+ (const Vector< n > &a, const Vector< n > &b)
 Adds two vectors.

Vector< n > operator- (const Vector< n > &a, const Vector< n > &b)
 Subtracts two vectors.

double operator * (const Vector< n > &a, const Vector< n > &b)
 Finds the dot product (aka scalar product) of two vectors.

std::ostream & operator<< (std::ostream &, const Vector< n > &)
 Outputs a Vector to a C++ ostream.


Detailed Description

template<unsigned int n>
class Vector< n >

Generic n-dimensional vector.

Definition at line 191 of file geometry.hh.


Member Function Documentation

template<unsigned int n>
bool Vector< n >::isNormalized  )  const [inline]
 

Determines if the vector is normalized.

This is useful for inside assertions. Due to floating point imprecision, this is actually a reasonable approximation of a normalization test.

See also:
NORMAL_EPSILON

Definition at line 219 of file geometry.hh.

References abs(), Vector< n >::getLength(), and Vector< n >::NORMAL_EPSILON.

template<unsigned int n>
void Vector< n >::normalize  ) 
 

Normalizes this vector, adjusting it to unit length.

Due to floating point imprecision, this is actually a reasonable approximation of normalization.

Precondition:
The vector's current length is non-zero.

Definition at line 59 of file geometry.impl.

References Vector< n >::data, and Vector< n >::getLength().

template<unsigned int n>
void Vector< n >::translateGL  )  const
 

Translates the current GL context by this vector.

Precondition:
This is a one-, two-, or three-dimensional vector.

Definition at line 67 of file geometry.impl.

References Vector< n >::data.


Friends And Related Function Documentation

template<unsigned int n>
std::ostream & operator<< std::ostream &  ,
const Vector< n > & 
[related]
 

Outputs a Vector to a C++ ostream.

The output will be "v<1,2,...,n>".

Definition at line 95 of file geometry.impl.


Member Data Documentation

template<unsigned int n>
Matrix<n+1,1> Vector< n >::data [private]
 

The matrix representing this point.

Position (i,0) is the value of dimension i. Position (n,0) is always 0.0.

Definition at line 263 of file geometry.hh.

Referenced by Vector< n >::getLength(), Vector< n >::getMatrix(), Vector< n >::normalize(), Vector< n >::operator *=(), Vector< n >::operator+=(), Vector< n >::operator-(), Vector< n >::operator-=(), Vector< n >::operator/=(), Vector< n >::operator[](), Vector< n >::translateGL(), and Vector< n >::Vector().

template<unsigned int n>
const double Vector< n >::NORMAL_EPSILON = 1e-6 [static]
 

The epsilon to use for determining if a vector is normalized or not.

See also:
isNormalized

Definition at line 4 of file geometry.impl.

Referenced by Vector< n >::isNormalized().


The documentation for this class was generated from the following files:
Generated on Fri Feb 4 10:41:11 2005 for tracer by doxygen 1.3.5