My Project
Public Member Functions | Public Attributes | Friends | List of all members
ParaEngine::DVector3 Class Reference

3-dimensional vector with double precision. More...

#include <ParaDVector3.h>

Public Member Functions

 DVector3 (const double fX, const double fY, const double fZ)
 
 DVector3 (const double afCoordinate[3])
 
 DVector3 (const int afCoordinate[3])
 
 DVector3 (double *const r)
 
 DVector3 (const double scaler)
 
 DVector3 (const Vector3 &vFrom)
 
double operator[] (const size_t i) const
 
double & operator[] (const size_t i)
 
double * ptr ()
 Pointer accessor for direct copying.
 
const double * ptr () const
 Pointer accessor for direct copying.
 
 operator Vector3 () const
 convert to a vector3
 
DVector3operator= (const DVector3 &rkVector)
 Assigns the value of the other vector. More...
 
DVector3operator= (const Vector3 &rkVector)
 
DVector3operator= (const double fScaler)
 
bool operator== (const DVector3 &rkVector) const
 
bool operator!= (const DVector3 &rkVector) const
 
DVector3 operator+ (const DVector3 &rkVector) const
 
DVector3 operator+ (const Vector3 &rkVector) const
 
DVector3 operator- (const DVector3 &rkVector) const
 
DVector3 operator- (const Vector3 &rkVector) const
 
DVector3 operator* (const double fScalar) const
 
DVector3 operator% (const DVector3 &rhs) const
 special cross product
 
DVector3 operator* (const DVector3 &rhs) const
 
DVector3 operator/ (const double fScalar) const
 
DVector3 operator/ (const DVector3 &rhs) const
 
const DVector3operator+ () const
 
DVector3 operator- () const
 
DVector3operator+= (const DVector3 &rkVector)
 
DVector3operator+= (const Vector3 &rkVector)
 
DVector3operator+= (const double fScalar)
 
DVector3operator-= (const DVector3 &rkVector)
 
DVector3operator-= (const Vector3 &rkVector)
 
DVector3operator-= (const double fScalar)
 
DVector3operator*= (const double fScalar)
 
DVector3operator*= (const DVector3 &rkVector)
 
DVector3operator/= (const double fScalar)
 
DVector3operator/= (const DVector3 &rkVector)
 
double length () const
 Returns the length (magnitude) of the vector. More...
 
double squaredLength () const
 Returns the square of the length(magnitude) of the vector. More...
 
double distance (const DVector3 &rhs) const
 Returns the distance to another vector. More...
 
double squaredDistance (const DVector3 &rhs) const
 Returns the square of the distance to another vector. More...
 
double dotProduct (const DVector3 &vec) const
 Calculates the dot (scalar) product of this vector with another. More...
 
double absDotProduct (const DVector3 &vec) const
 Calculates the absolute dot (scalar) product of this vector with another. More...
 
double normalise ()
 Normalises the vector. More...
 
DVector3 crossProduct (const DVector3 &rkVector) const
 Calculates the cross-product of 2 vectors, i.e. More...
 
DVector3 midPoint (const DVector3 &vec) const
 Returns a vector at a point half way between this and the passed in vector.
 
bool operator< (const DVector3 &rhs) const
 Returns true if the vector's scalar components are all greater that the ones of the vector it is compared against.
 
bool operator> (const DVector3 &rhs) const
 Returns true if the vector's scalar components are all smaller that the ones of the vector it is compared against.
 
void makeFloor (const DVector3 &cmp)
 Sets this vector's components to the minimum of its own and the ones of the passed in vector. More...
 
void makeCeil (const DVector3 &cmp)
 Sets this vector's components to the maximum of its own and the ones of the passed in vector. More...
 
bool isZeroLength (void) const
 Returns true if this vector is zero length. More...
 
DVector3 normalisedCopy (void) const
 As normalise, except that this vector is unaffected and the normalized vector is returned as a copy. More...
 
DVector3 reflect (const DVector3 &normal) const
 Calculates a reflection vector to the plane with the given normal . More...
 
bool positionEquals (const Vector3 &rhs, float tolerance=1e-03) const
 Returns whether this vector is within a positional tolerance of another floating precision vector. More...
 
bool positionCloses (const DVector3 &rhs, float tolerance=1e-03f) const
 Returns whether this vector is within a positional tolerance of another vector, also take scale of the vectors into account. More...
 
bool directionEquals (const DVector3 &rhs, const Radian &tolerance) const
 Returns whether this vector is within a directional tolerance of another vector. More...
 

Public Attributes

double x
 
double y
 
double z
 

Friends

DVector3 operator* (const double fScalar, const DVector3 &rkVector)
 
DVector3 operator/ (const double fScalar, const DVector3 &rkVector)
 
DVector3 operator+ (const DVector3 &lhs, const double rhs)
 
DVector3 operator+ (const double lhs, const DVector3 &rhs)
 
DVector3 operator- (const DVector3 &lhs, const double rhs)
 
DVector3 operator- (const double lhs, const DVector3 &rhs)
 
std::ostream & operator<< (std::ostream &o, const DVector3 &v)
 Function for writing to a stream.
 

Detailed Description

3-dimensional vector with double precision.

Remarks
A direction in 3D space represented as distances along the 3 orthogonal axes (x, y, z). Note that positions, directions and scaling factors can be represented by a vector, depending on how you interpret the values.

Member Function Documentation

§ absDotProduct()

double ParaEngine::DVector3::absDotProduct ( const DVector3 vec) const
inline

Calculates the absolute dot (scalar) product of this vector with another.

Remarks
This function work similar dotProduct, except it use absolute value of each component of the vector to computing.
Parameters
vecVector with which to calculate the absolute dot product (together with this one).
Returns
A double representing the absolute dot product value.

§ crossProduct()

DVector3 ParaEngine::DVector3::crossProduct ( const DVector3 rkVector) const
inline

Calculates the cross-product of 2 vectors, i.e.

the vector that lies perpendicular to them both.

Remarks
The cross-product is normally used to calculate the normal vector of a plane, by calculating the cross-product of 2 non-equivalent vectors which lie on the plane (e.g. 2 edges of a triangle).
Parameters
vecVector which, together with this one, will be used to calculate the cross-product.
Returns
A vector which is the result of the cross-product. This vector will NOT be normalised, to maximise efficiency
  • call DVector3::normalise on the result if you wish this to be done. As for which side the resultant vector will be on, the returned vector will be on the side from which the arc from 'this' to rkVector is anticlockwise, e.g. UNIT_Y.crossProduct(UNIT_Z) = UNIT_X, whilst UNIT_Z.crossProduct(UNIT_Y) = -UNIT_X. This is because OGRE uses a right-handed coordinate system.
For a clearer explanation, look a the left and the bottom edges of your monitor's screen. Assume that the first vector is the left edge and the second vector is the bottom edge, both of them starting from the lower-left corner of the screen. The resulting vector is going to be perpendicular to both of them and will go inside the screen, towards the cathode tube (assuming you're using a CRT monitor, of course).

§ directionEquals()

bool ParaEngine::DVector3::directionEquals ( const DVector3 rhs,
const Radian tolerance 
) const
inline

Returns whether this vector is within a directional tolerance of another vector.

Parameters
rhsThe vector to compare with
toleranceThe maximum angle by which the vectors may vary and still be considered equal
Note
Both vectors should be normalized.

§ distance()

double ParaEngine::DVector3::distance ( const DVector3 rhs) const
inline

Returns the distance to another vector.

Warning
This operation requires a square root and is expensive in terms of CPU operations. If you don't need to know the exact distance (e.g. for just comparing distances) use squaredDistance() instead.

§ dotProduct()

double ParaEngine::DVector3::dotProduct ( const DVector3 vec) const
inline

Calculates the dot (scalar) product of this vector with another.

Remarks
The dot product can be used to calculate the angle between 2 vectors. If both are unit vectors, the dot product is the cosine of the angle; otherwise the dot product must be divided by the product of the lengths of both vectors to get the cosine of the angle. This result can further be used to calculate the distance of a point from a plane.
Parameters
vecVector with which to calculate the dot product (together with this one).
Returns
A double representing the dot product value.

§ isZeroLength()

bool ParaEngine::DVector3::isZeroLength ( void  ) const
inline

Returns true if this vector is zero length.

§ length()

double ParaEngine::DVector3::length ( ) const
inline

Returns the length (magnitude) of the vector.

Warning
This operation requires a square root and is expensive in terms of CPU operations. If you don't need to know the exact length (e.g. for just comparing lengths) use squaredLength() instead.

§ makeCeil()

void ParaEngine::DVector3::makeCeil ( const DVector3 cmp)
inline

Sets this vector's components to the maximum of its own and the ones of the passed in vector.

Remarks
'Maximum' in this case means the combination of the highest value of x, y and z from both vectors. Highest is taken just numerically, not magnitude, so 1 > -3.

§ makeFloor()

void ParaEngine::DVector3::makeFloor ( const DVector3 cmp)
inline

Sets this vector's components to the minimum of its own and the ones of the passed in vector.

Remarks
'Minimum' in this case means the combination of the lowest value of x, y and z from both vectors. Lowest is taken just numerically, not magnitude, so -1 < 0.

§ normalise()

double ParaEngine::DVector3::normalise ( )
inline

Normalises the vector.

Remarks
This method normalises the vector such that it's length / magnitude is 1. The result is called a unit vector.
Note
This function will not crash for zero-sized vectors, but there will be no changes made to their components.
Returns
The previous length of the vector.

§ normalisedCopy()

DVector3 ParaEngine::DVector3::normalisedCopy ( void  ) const
inline

As normalise, except that this vector is unaffected and the normalized vector is returned as a copy.

§ operator=()

DVector3& ParaEngine::DVector3::operator= ( const DVector3 rkVector)
inline

Assigns the value of the other vector.

Parameters
rkVectorThe other vector

§ positionCloses()

bool ParaEngine::DVector3::positionCloses ( const DVector3 rhs,
float  tolerance = 1e-03f 
) const
inline

Returns whether this vector is within a positional tolerance of another vector, also take scale of the vectors into account.

Parameters
rhsThe vector to compare with
toleranceThe amount (related to the scale of vectors) that distance of the vector may vary by and still be considered close

§ positionEquals()

bool ParaEngine::DVector3::positionEquals ( const Vector3 rhs,
float  tolerance = 1e-03 
) const
inline

Returns whether this vector is within a positional tolerance of another floating precision vector.

Parameters
rhsThe vector to compare with
toleranceThe amount that each element of the vector may vary by and still be considered equal

§ reflect()

DVector3 ParaEngine::DVector3::reflect ( const DVector3 normal) const
inline

Calculates a reflection vector to the plane with the given normal .

Remarks
NB assumes 'this' is pointing AWAY FROM the plane, invert if it is not.

§ squaredDistance()

double ParaEngine::DVector3::squaredDistance ( const DVector3 rhs) const
inline

Returns the square of the distance to another vector.

Remarks
This method is for efficiency - calculating the actual distance to another vector requires a square root, which is expensive in terms of the operations required. This method returns the square of the distance to another vector, i.e. the same as the distance but before the square root is taken. Use this if you want to find the longest / shortest distance without incurring the square root.

§ squaredLength()

double ParaEngine::DVector3::squaredLength ( ) const
inline

Returns the square of the length(magnitude) of the vector.

Remarks
This method is for efficiency - calculating the actual length of a vector requires a square root, which is expensive in terms of the operations required. This method returns the square of the length of the vector, i.e. the same as the length but before the square root is taken. Use this if you want to find the longest / shortest vector without incurring the square root.

The documentation for this class was generated from the following file: