Vector3D< T > Class Template Reference

A templatized math class representing a 3-dimensional vector. More...

#include <rimPhysicsVector3D.h>

List of all members.

Public Member Functions

 Vector3D ()
 Create a new 3D vector with all elements equal to zero.
 Vector3D (T value)
 Create a new 3D vector with all elements equal to a single value.
 Vector3D (T *array)
 Create a new 3D vector from a pointer to a 3 element array.
 Vector3D (T newX, T newY, T newZ)
 Create a new 3D vector by specifying it's x, y, and z values.
 Vector3D (const Vector3D< T > &vector)
 Create a new 3D vector from an existing vector (copy it).
template<typename U>
 Vector3D (const Vector3D< U > &vector)
 Create a new 3D vector from an existing vector (copy it), templatized version.
 Vector3D (const Vector2D< T > &vector, T newZ)
 Create a new 3D vector from a 2D vector and a value for the Z coordinate.
 Vector3D (T newX, const Vector2D< T > &vector)
 Create a new 3D vector from a value for the X coordinate and a 2D vector.
getMagnitude () const
 Get the magnitude of this vector (the length).
getMagnitudeSquared () const
 Get the square of the magnitude of this vector.
Vector3D< T > normalize () const
 Return a normalized version of this vector.
Vector3D< T > projectOn (const Vector3D< T > &vector) const
 Project this vector on another vector and return the projected vector.
getDistanceTo (const Vector3D< T > &vector) const
 Get the distance from this vector to another in 3D space.
getDistanceToSquared (const Vector3D< T > &vector) const
 Get the square of the distance from this vector to another in 3D space.
const T * getCString () const
 Get a shallow array representation of this vector.
T * toArray () const
 Get an array copy of this vector.
getX () const
 Get the X coordinate of this vector.
getY () const
 Get the Y coordinate of this vector.
getZ () const
 Get the Z coordinate of this vector.
Vector2D< T > getXY () const
 Get a 2D vector containing the X and Y elements of this 3D vector.
Vector2D< T > getXZ () const
 Get a 2D vector containing the X and Z elements of this 3D vector.
Vector2D< T > getYZ () const
 Get a 2D vector containing the Y and Z elements of this 3D vector.
get (int index) const
 Get an indexed coordinate of this vector.
void setX (T newX)
 Set the X coordinate of the vector to the specified value.
void setY (T newY)
 Set the Y coordinate of the vector to the specified value.
void setZ (T newZ)
 Set the Z coordinate of the vector to the specified value.
void set (T newX, T newY, T newZ)
 Set the X, Y, and Z coordinates of the vector to the specified values.
void set (int index, T newValue)
 Set an indexed coordinate of this vector.
template<typename U>
 operator Vector3D< U > ()
 This operator casts this vector to another with different template paramter.
template<typename U>
 operator Vector3D< U > () const
 This operator casts this vector to another with different template paramter.
Vector3D< T > operator- () const
 Negate a vector.
Vector3D< T > operator+ () const
 Postive a vector, returning a copy of it. Operator does nothing.
Vector3D< T > operator+ (const Vector3D< T > &vector) const
 Add this vector to another and return the result.
Vector3D< T > operator+ (const T &value) const
 Add a value to every component of this vector.
Vector3D< T > operator- (const Vector3D< T > &vector) const
 Subtract a vector from this vector component-wise and return the result.
Vector3D< T > operator- (const T &value) const
 Subtract a value from every component of this vector.
Vector3D< T > operator * (const Vector3D< T > &vector) const
 Multiply component-wise this vector and another vector.
Vector3D< T > operator * (const T &value) const
 Multiply every component of this vector by a value and return the result.
Vector3D< T > operator/ (const T &value) const
 Divide every component of this vector by a value and return the result.
Vector3D< T > & operator+= (const Vector3D< T > &vector)
 Add a vector to this vector, modifying this original vector.
Vector3D< T > & operator-= (const Vector3D< T > &vector)
 Subtract a vector from this vector, modifying this original vector.
Vector3D< T > & operator *= (const Vector3D< T > &vector)
 Multiply component-wise this vector and another vector and modify this vector.
Vector3D< T > & operator+= (const T &value)
 Add a value to each component of this vector, modifying it.
Vector3D< T > & operator-= (const T &value)
 Subtract a value from each component of this vector, modifying it.
Vector3D< T > & operator *= (const T &value)
 Multiply a value with each component of this vector, modifying it.
Vector3D< T > & operator/= (const T &value)
 Divide each component of this vector by a value, modifying it.

Public Attributes

x
 The X coordinate of a 3D vector.
y
 The Y coordinate of a 3D vector.
z
 The Z coordinate of a 3D vector.

Static Public Attributes

static const Vector3D< T > ZERO
 A constant vector with all elements equal to zero.


Detailed Description

template<typename T>
class Vector3D< T >

A templatized math class representing a 3-dimensional vector.

Constructor & Destructor Documentation

template<typename T>
Vector3D< T >::Vector3D (  )  [inline]

Create a new 3D vector with all elements equal to zero.

template<typename T>
Vector3D< T >::Vector3D ( value  )  [inline, explicit]

Create a new 3D vector with all elements equal to a single value.

This constructor creates a uniform 3D vector with all elements equal to each other and equal to the single constructor parameter value.

Parameters:
value - The value to set all elements of the vector to.

template<typename T>
Vector3D< T >::Vector3D ( T *  array  )  [inline]

Create a new 3D vector from a pointer to a 3 element array.

This constructor takes a pointer to an array of 3 values and sets it's x, y, and z coordinates to be the 0th, 1th, and 2th indexed values in the array. No error checking is performed, so make sure to pass in a correct array of values or expect the worst.

Parameters:
array - An indexed array of 3 values for the vector's coordinates.

template<typename T>
Vector3D< T >::Vector3D ( newX,
newY,
newZ 
) [inline]

Create a new 3D vector by specifying it's x, y, and z values.

This constructor sets each of the vector's x, y, and z coordinate values to be the 1st, 2nd, and 3rd parameters of the constructor, respectively.

Parameters:
newX - The X coordinate of the new vector.
newY - The Y coordinate of the new vector.
newZ - The Z coordinate of the new vector.

template<typename T>
Vector3D< T >::Vector3D ( const Vector3D< T > &  vector  )  [inline]

Create a new 3D vector from an existing vector (copy it).

This constructor takes the x, y, and z values of the vector parameter and sets the coordinates of this vector to be the same.

Parameters:
vector - The vector to be copied.

template<typename T>
template<typename U>
Vector3D< T >::Vector3D ( const Vector3D< U > &  vector  )  [inline]

Create a new 3D vector from an existing vector (copy it), templatized version.

This constructor takes the x, y, and z values of the vector parameter and sets the coordinates of this vector to be the same. This is a templatized version of the above copy constructor.

Parameters:
vector - The vector to be copied.

template<typename T>
Vector3D< T >::Vector3D ( const Vector2D< T > &  vector,
newZ 
) [inline]

Create a new 3D vector from a 2D vector and a value for the Z coordinate.

This constructor takes the x and y coordinates of the first parameter, a 2D vector, and sets the x and y coordinates of this vector to be the same. It then takes the 2nd paramter, a value, and sets the z coordinate of this vector to be that value.

Parameters:
vector - A 2D vector for the x and y coordinates of this vector.
newZ - The value for the Z coordinate of this vector.

template<typename T>
Vector3D< T >::Vector3D ( newX,
const Vector2D< T > &  vector 
) [inline]

Create a new 3D vector from a value for the X coordinate and a 2D vector.

This constructor sets the x coordinate of this vector to be the same as the value of the first parameter, and then sets the y and z coordinates of this vector to be the x and y coordinates of the 2nd parameter, a 2D vector.

Parameters:
newX - The value for the x coordinate of this vector.
vector - A 2D vector for the y and z coordinates of this vector.


Member Function Documentation

template<typename T>
T Vector3D< T >::getMagnitude (  )  const [inline]

Get the magnitude of this vector (the length).

This Method finds the magnitude of this vector using the formula: magnitude = sqrt( x*x + y*y + z*z ). It's value is always positive.

Returns:
the magnitude of the vector.

template<typename T>
T Vector3D< T >::getMagnitudeSquared (  )  const [inline]

Get the square of the magnitude of this vector.

This method is provided in addition to the above getMagnitude() method in order to provide a faster alternate way of computing a magnitude-like quantity for the vector. For instance, when computing whether or not the magnitude of a vector is greater than some value, one can instead compare the square of the magnitude to the square of the value (avoiding the square root operation), with the same result.

Returns:
the square of the magnitude of this vector.

template<typename T>
Vector3D<T> Vector3D< T >::normalize (  )  const [inline]

Return a normalized version of this vector.

This method normalizes this vector by dividing each component by the vector's magnitude and returning the result. This method does not modify the original vector.

Returns:
a normalized version of this vector.

template<typename T>
Vector3D<T> Vector3D< T >::projectOn ( const Vector3D< T > &  vector  )  const [inline]

Project this vector on another vector and return the projected vector.

This method computes the vectoral projection of this vector onto another, and returns the resulting vector. This result should be parallel (within the precision of the vectors) to the original parameter vector. This method does not modify either original vector.

Parameters:
vector - The vector to project this vector on.
Returns:
the vectoral projection onto the parameter vector of this vector.

template<typename T>
T Vector3D< T >::getDistanceTo ( const Vector3D< T > &  vector  )  const [inline]

Get the distance from this vector to another in 3D space.

This method essentially computes the magnitude of the subtraction of this vector minus the parameter vector. This treats each vector as a point in 3D space.

Parameters:
vector - the vector to query the distance to.
Returns:
the distance to the parameter vector.

template<typename T>
T Vector3D< T >::getDistanceToSquared ( const Vector3D< T > &  vector  )  const [inline]

Get the square of the distance from this vector to another in 3D space.

This method essentially computes the magnitude squared of the subtraction of this vector minus the parameter vector. This treats each vector as a point in 3D space. This function can be used for faster distance comparisions because it avoids the square root operation of the getDistanceTo() method.

Parameters:
vector - the vector to query the distance to.
Returns:
the distance to the parameter vector.

template<typename T>
const T* Vector3D< T >::getCString (  )  const [inline]

Get a shallow array representation of this vector.

This method returns a pointer to the address of the X coordinate of the vector and does not do any copying of the elements. Therefore, this method should only be used where one needs an array representation of a vector without having to allocate more memory and copy the vector.

Returns:
A pointer to a shallow array copy of this vector.

template<typename T>
T* Vector3D< T >::toArray (  )  const [inline]

Get an array copy of this vector.

This method copies the elements of this vector into a 3 element long array. This array is a deep copy, and must be deleted when it is no longer needed, or else a memory leak will occur.

Returns:
A pointer to a deep array copy of this vector.

template<typename T>
T Vector3D< T >::getX (  )  const [inline]

Get the X coordinate of this vector.

template<typename T>
T Vector3D< T >::getY (  )  const [inline]

Get the Y coordinate of this vector.

template<typename T>
T Vector3D< T >::getZ (  )  const [inline]

Get the Z coordinate of this vector.

template<typename T>
Vector2D<T> Vector3D< T >::getXY (  )  const [inline]

Get a 2D vector containing the X and Y elements of this 3D vector.

template<typename T>
Vector2D<T> Vector3D< T >::getXZ (  )  const [inline]

Get a 2D vector containing the X and Z elements of this 3D vector.

template<typename T>
Vector2D<T> Vector3D< T >::getYZ (  )  const [inline]

Get a 2D vector containing the Y and Z elements of this 3D vector.

template<typename T>
T Vector3D< T >::get ( int  index  )  const [inline]

Get an indexed coordinate of this vector.

This method takes an index with the possible values 0, 1, or 2, and returns the X, Y, or Z coordinate of this vector, respectively. There is no error checking performed (for speed), so make sure that the index is in the valid bounds mentioned above, or else bad things could happen.

Parameters:
index - An index into the vector with 0 = X, 1 = Y, 2 = Z.
Returns:
the value of the vector associated with the given index.

template<typename T>
void Vector3D< T >::setX ( newX  )  [inline]

Set the X coordinate of the vector to the specified value.

template<typename T>
void Vector3D< T >::setY ( newY  )  [inline]

Set the Y coordinate of the vector to the specified value.

template<typename T>
void Vector3D< T >::setZ ( newZ  )  [inline]

Set the Z coordinate of the vector to the specified value.

template<typename T>
void Vector3D< T >::set ( newX,
newY,
newZ 
) [inline]

Set the X, Y, and Z coordinates of the vector to the specified values.

This method takes 3 parameter representing the 3 coordinates of this vector and sets this vector's coordinates to have those values.

Parameters:
newX - The new X coordinate of the vector.
newY - The new Y coordinate of the vector.
newZ - The new Z coordinate of the vector.

template<typename T>
void Vector3D< T >::set ( int  index,
newValue 
) [inline]

Set an indexed coordinate of this vector.

This method takes an index with the possible values 0, 1, or 2, and sets the X, Y, or Z coordinate of this vector to be the new value, respectively. There is no error checking performed (for speed), so make sure that the index is in the valid bounds mentioned above, or else bad things could happen.

Parameters:
index - An index into the vector with 0 = X, 1 = Y, 2 = Z.
newValue - The new value of the coordinate with the given index.

template<typename T>
template<typename U>
Vector3D< T >::operator Vector3D< U > (  )  [inline]

This operator casts this vector to another with different template paramter.

This method provides an operator for the casting of this vector to another vector with a potentially different template paramter.

Returns:
the cast version of this vector.

template<typename T>
template<typename U>
Vector3D< T >::operator Vector3D< U > (  )  const [inline]

This operator casts this vector to another with different template paramter.

This method provides an operator for the casting of this vector to another vector with a potentially different template paramter. This is the const version of this operator.

Returns:
the cast version of this vector.

template<typename T>
Vector3D<T> Vector3D< T >::operator- (  )  const [inline]

Negate a vector.

This method returns the negation of a vector, making it point in the opposite direction. It does not modify the original vector.

Returns:
the negation of the original vector.

template<typename T>
Vector3D<T> Vector3D< T >::operator+ (  )  const [inline]

Postive a vector, returning a copy of it. Operator does nothing.

This operator doesn't do anything but return the original value of the vector that it affects.

Returns:
the same vector as the orignal vector.

template<typename T>
Vector3D<T> Vector3D< T >::operator+ ( const Vector3D< T > &  vector  )  const [inline]

Add this vector to another and return the result.

This method adds another vector to this one, component-wise, and returns this addition. It does not modify either of the original vectors.

Parameters:
vector - The vector to add to this one.
Returns:
The addition of this vector and the parameter.

template<typename T>
Vector3D<T> Vector3D< T >::operator+ ( const T &  value  )  const [inline]

Add a value to every component of this vector.

This method adds the value parameter to every component of the vector, and returns a vector representing this result. It does not modifiy the original vector.

Parameters:
value - The value to add to all components of this vector.
Returns:
The resulting vector of this addition.

template<typename T>
Vector3D<T> Vector3D< T >::operator- ( const Vector3D< T > &  vector  )  const [inline]

Subtract a vector from this vector component-wise and return the result.

This method subtracts another vector from this one, component-wise, and returns this subtraction. It does not modify either of the original vectors.

Parameters:
vector - The vector to subtract from this one.
Returns:
The subtraction of the the parameter from this vector.

template<typename T>
Vector3D<T> Vector3D< T >::operator- ( const T &  value  )  const [inline]

Subtract a value from every component of this vector.

This method subtracts the value parameter from every component of the vector, and returns a vector representing this result. It does not modifiy the original vector.

Parameters:
value - The value to subtract from all components of this vector.
Returns:
The resulting vector of this subtraction.

template<typename T>
Vector3D<T> Vector3D< T >::operator * ( const Vector3D< T > &  vector  )  const [inline]

Multiply component-wise this vector and another vector.

This operator multiplies each component of this vector by the corresponding component of the other vector and returns a vector representing this result. It does not modify either original vector.

Parameters:
vector - The vector to multiply this vector by.
Returns:
The result of the multiplication.

template<typename T>
Vector3D<T> Vector3D< T >::operator * ( const T &  value  )  const [inline]

Multiply every component of this vector by a value and return the result.

This method multiplies the value parameter with every component of the vector, and returns a vector representing this result. It does not modifiy the original vector.

Parameters:
value - The value to multiplly with all components of this vector.
Returns:
The resulting vector of this multiplication.

template<typename T>
Vector3D<T> Vector3D< T >::operator/ ( const T &  value  )  const [inline]

Divide every component of this vector by a value and return the result.

This method Divides every component of the vector by the value parameter, and returns a vector representing this result. It does not modifiy the original vector.

Parameters:
value - The value to divide all components of this vector by.
Returns:
The resulting vector of this division.

template<typename T>
Vector3D<T>& Vector3D< T >::operator+= ( const Vector3D< T > &  vector  )  [inline]

Add a vector to this vector, modifying this original vector.

This method adds another vector to this vector, component-wise, and sets this vector to have the result of this addition.

Parameters:
vector - The vector to add to this vector.
Returns:
A reference to this modified vector.

template<typename T>
Vector3D<T>& Vector3D< T >::operator-= ( const Vector3D< T > &  vector  )  [inline]

Subtract a vector from this vector, modifying this original vector.

This method subtracts another vector from this vector, component-wise, and sets this vector to have the result of this subtraction.

Parameters:
vector - The vector to subtract from this vector.
Returns:
A reference to this modified vector.

template<typename T>
Vector3D<T>& Vector3D< T >::operator *= ( const Vector3D< T > &  vector  )  [inline]

Multiply component-wise this vector and another vector and modify this vector.

This operator multiplies each component of this vector by the corresponding component of the other vector and modifies this vector to contain the result.

Parameters:
vector - The vector to multiply this vector by.
Returns:
A reference to this modified vector.

template<typename T>
Vector3D<T>& Vector3D< T >::operator+= ( const T &  value  )  [inline]

Add a value to each component of this vector, modifying it.

This operator adds a value to each component of this vector and modifies this vector to store the result.

Parameters:
value - The value to add to every component of this vector.
Returns:
A reference to this modified vector.

template<typename T>
Vector3D<T>& Vector3D< T >::operator-= ( const T &  value  )  [inline]

Subtract a value from each component of this vector, modifying it.

This operator subtracts a value from each component of this vector and modifies this vector to store the result.

Parameters:
value - The value to subtract from every component of this vector.
Returns:
A reference to this modified vector.

template<typename T>
Vector3D<T>& Vector3D< T >::operator *= ( const T &  value  )  [inline]

Multiply a value with each component of this vector, modifying it.

This operator multiplies a value with each component of this vector and modifies this vector to store the result.

Parameters:
value - The value to multiply with every component of this vector.
Returns:
A reference to this modified vector.

template<typename T>
Vector3D<T>& Vector3D< T >::operator/= ( const T &  value  )  [inline]

Divide each component of this vector by a value, modifying it.

This operator Divides each component of this vector by value and modifies this vector to store the result.

Parameters:
value - The value to multiply with every component of this vector.
Returns:
A reference to this modified vector.


Member Data Documentation

template<typename T>
T Vector3D< T >::x

The X coordinate of a 3D vector.

template<typename T>
T Vector3D< T >::y

The Y coordinate of a 3D vector.

template<typename T>
T Vector3D< T >::z

The Z coordinate of a 3D vector.

template<typename T>
const Vector3D< T > Vector3D< T >::ZERO [inline, static]

A constant vector with all elements equal to zero.


The documentation for this class was generated from the following file:
Generated on Tue Aug 26 00:03:21 2008 for Rim Physics by  doxygen 1.5.4