chai3d::cVector3d Struct Reference

This class implements a 3D vector. More...

#include <CVector3d.h>

Public Member Functions

 cVector3d ()
 
 cVector3d (const double a_x, const double a_y, const double a_z)
 Constructor of cVector3d. More...
 
 cVector3d (const cVector3d &a_vector)
 Constructor of cVector3d. More...
 
 cVector3d (const char *a_string)
 Constructor of cVector3d. More...
 
 cVector3d (const std::string &a_string)
 Constructor of cVector3d. More...
 
double x () const
 This method returns vector component x. More...
 
double y () const
 This method returns vector component y. More...
 
double z () const
 This method returns vector component z. More...
 
void x (const double a_value)
 This method sets vector component x. More...
 
void y (const double a_value)
 This method sets vector component y. More...
 
void z (const double a_value)
 This method sets vector component z. More...
 
void zero ()
 This method clears all vector components with zeros. More...
 
double get (const unsigned int &a_component) const
 This method returns the i th component of the vector. More...
 
void set (const double &a_x, const double &a_y, const double &a_z)
 This method initializes this vector with components x, y, and z passed as arguments. More...
 
bool set (const char *a_initStr)
 This method initializes this vector from an input ANSI spring. More...
 
bool set (const std::string &a_initStr)
 This method initializes this vector from and input string. More...
 
void copyto (cVector3d &a_destination) const
 This method copies the content of this vector to another. More...
 
void copyfrom (const cVector3d &a_source)
 This method copies the content of a vector to this one. More...
 
void add (const cVector3d &a_vector)
 This method computes the addition of this vector with another. More...
 
void add (const double &a_x, const double &a_y, const double &a_z)
 This method computes the addition of this vector with another. More...
 
void addr (const cVector3d &a_vector, cVector3d &a_result) const
 This method computes the addition of this vector with another. More...
 
void addr (const double &a_x, const double &a_y, const double &a_z, cVector3d &a_result) const
 This method computes the addition of this vector with another. More...
 
void sub (const cVector3d &a_vector)
 This method computes the subtraction of this vector with another. More...
 
void sub (const double &a_x, const double &a_y, const double &a_z)
 This method computes the subtraction of this vector with another. More...
 
void subr (const cVector3d &a_vector, cVector3d &a_result) const
 This method computes the subtraction of this vector with another. More...
 
void subr (const double &a_x, const double &a_y, const double &a_z, cVector3d &a_result) const
 This method computes the subtraction of this vector with another. More...
 
void mul (const double &a_scalar)
 This method computes the multiplication of this vector with a scalar. More...
 
void mul (const double &a_scalar0, const double &a_scalar1, const double &a_scalar2)
 This method computes the multiplication of each component of this vector by a set of scalars. More...
 
void mulr (const double &a_scalar, cVector3d &a_result) const
 This method computes the multiplication of this vector with a scalar. More...
 
void mulr (const double &a_scalar0, const double &a_scalar1, const double &a_scalar2, cVector3d &a_result) const
 This method computes the multiplication of each component of this vector by a set of scalars. More...
 
void mulElement (const cVector3d &a_vector)
 This method computes the element-by-element product between this vector and another. More...
 
void mulElementr (const cVector3d &a_vector, cVector3d &a_result) const
 This method computes the element-by-element product between this vector and another. More...
 
void div (const double &a_scalar)
 This method computes the division of this vector with a scalar. More...
 
void divr (const double &a_scalar, cVector3d &a_result) const
 This method computes the division of this vector with a scalar. More...
 
void negate ()
 This method computes the negated vector. More...
 
void negater (cVector3d &a_result) const
 This method computes the negated vector. More...
 
void cross (const cVector3d &a_vector)
 This method computes the cross product. More...
 
void crossr (const cVector3d &a_vector, cVector3d &a_result) const
 This method computes the cross product. More...
 
double dot (const cVector3d &a_vector) const
 This method computes the dot product between this vector and another. More...
 
double length () const
 This method computes the Euclidean norm of this vector. More...
 
double lengthsq () const
 This method computes the squared value of the Euclidean norm of this vector. More...
 
void normalize ()
 This method normalizes this vector to length 1. More...
 
void normalizer (cVector3d &a_result) const
 This method normalizes this vector to length 1. More...
 
void clamp (const double &a_maxLength)
 This method clamps this vector to a maximum desired length. More...
 
double distance (const cVector3d &a_vector) const
 This method computes the distance between two points. More...
 
double distancesq (const cVector3d &a_vector) const
 This method computes the squared value distance between two points. More...
 
bool equals (const cVector3d &a_vector, const double a_epsilon=0.0) const
 This method performs an equality test between two vectors. More...
 
std::string str (const unsigned int a_precision=2) const
 This method convert this vector into a string. More...
 
void operator/= (const double &a_val)
 An overloaded /= operator for vector/scalar division. More...
 
void operator*= (const double &a_val)
 An overloaded *= operator for vector/scalar multiplication. More...
 
void operator+= (const cVector3d &a_input)
 An overloaded += operator for vector/vector addition. More...
 
void operator-= (const cVector3d &a_input)
 An overloaded -= operator for vector/vector subtraction. More...
 
double & operator() (const int a_index)
 An overloaded () operator. More...
 
const double & operator() (const int a_index) const
 An overloaded () operator. More...
 

Detailed Description

This class implement a 3D vector that provides storage for a 3 dimensional double precision floating point vector as well as basic floating point arithmetic operations.

Constructor & Destructor Documentation

chai3d::cVector3d::cVector3d ( )
inline

Constructor of cVector3d.

chai3d::cVector3d::cVector3d ( const double  a_x,
const double  a_y,
const double  a_z 
)
inline

This constructor initializes a vector by passing three doubles by argument.

Parameters
a_xX value.
a_yY value.
a_zZ value.
chai3d::cVector3d::cVector3d ( const cVector3d a_vector)
inline

This constructor initializes a vector by passing a vector by argument.

Parameters
a_vectorVector.
chai3d::cVector3d::cVector3d ( const char *  a_string)
inline

This constructor initializes a vector by passing an ANSI string by argument.

Parameters
a_stringVector in string format.
chai3d::cVector3d::cVector3d ( const std::string &  a_string)
inline

This constructor initializes a vector by passing a string by argument.

Parameters
a_stringVector in string format.

Member Function Documentation

double chai3d::cVector3d::x ( ) const
inline
double chai3d::cVector3d::y ( ) const
inline
double chai3d::cVector3d::z ( ) const
inline
void chai3d::cVector3d::x ( const double  a_value)
inline
void chai3d::cVector3d::y ( const double  a_value)
inline
void chai3d::cVector3d::z ( const double  a_value)
inline
void chai3d::cVector3d::zero ( )
inline
double chai3d::cVector3d::get ( const unsigned int &  a_component) const
inline

This method returns the i th component of the vector.

Parameters
a_componentComponent index number (0,1, or 2).
Returns
Selected vector component.
void chai3d::cVector3d::set ( const double &  a_x,
const double &  a_y,
const double &  a_z 
)
inline

This method initializes this vector with arguments a_x, a_y, and a_z.

Parameters
a_xComponent x of vector.
a_yComponent y of vector.
a_zComponent z of vector.
bool chai3d::cVector3d::set ( const char *  a_initStr)
inline

This method initializes this vector from an input string of the form (x,y,z) . The following string formats are accepted:

  • (4.3,23,54)
  • 4.3 54 2.1
  • 4.5,7.8,9.1
    The methods expects three numbers, optionally preceded by '(' and whitespace, and separated by commas or whitespace.
Parameters
a_initStrVector in string format.
Returns
true if the conversion was successful, false otherwise.
bool chai3d::cVector3d::set ( const std::string &  a_initStr)
inline

This method initializes this vector from an input string of the form (x,y,z) . The following string formats are accepted:

  • (4.3,23,54)
  • 4.3 54 2.1
  • 4.5,7.8,9.1
    The methods expects three numbers, optionally preceded by '(' and whitespace, and separated by commas or whitespace.
Parameters
a_initStrVector in string format.
Returns
true if the conversion was successful, false otherwise.
void chai3d::cVector3d::copyto ( cVector3d a_destination) const
inline

This method copies components (x, y, z), of this vector to a vector passed as argument.

a_destination = this
Parameters
a_destinationDestination vector where data is copied.
void chai3d::cVector3d::copyfrom ( const cVector3d a_source)
inline

This method copies components (x, y, z) of a vector passed by argument to this one.

this = a_source
Parameters
a_sourceSource vector from where data is copied.
void chai3d::cVector3d::add ( const cVector3d a_vector)
inline

This method computes the addition of this vector with a vector passed by argument.
The result is stored in this vector.

this = this + a_vector
Parameters
a_vectorVector to be added to current one.
void chai3d::cVector3d::add ( const double &  a_x,
const double &  a_y,
const double &  a_z 
)
inline

This method computes the addition of this vector with a vector passed by argument.
The result is stored in this vector.

this = this + cVector3d(a_x, a_y, a_z)
Parameters
a_xComponent x of vector.
a_yComponent y of vector.
a_zComponent z of vector.
void chai3d::cVector3d::addr ( const cVector3d a_vector,
cVector3d a_result 
) const
inline

This method computes the addition of this vector with a vector passed by argument.
The result is stored in the result vector a_result that is passed by argument.

a_result = this + a_vector
Parameters
a_vectorVector to be added to current one.
a_resultResult of operation.
void chai3d::cVector3d::addr ( const double &  a_x,
const double &  a_y,
const double &  a_z,
cVector3d a_result 
) const
inline

This method computes the addition of this vector with a vector passed by argument.
The result is stored in the result vector a_result that is passed by argument.

a_result = this + cVector3d(a_x, a_y, a_z)
Parameters
a_xComponent x of vector.
a_yComponent y of vector.
a_zComponent z of vector.
a_resultResult of operation.
void chai3d::cVector3d::sub ( const cVector3d a_vector)
inline

This method computes the subtraction of this vector with a vector passed by argument.
The result is stored in this vector.

this = this - a_vector
Parameters
a_vectorVector to be subtracted from current one.
void chai3d::cVector3d::sub ( const double &  a_x,
const double &  a_y,
const double &  a_z 
)
inline

This method computes the subtraction of this vector with a vector passed by argument.
The result is stored in this vector.

this = this - cVector3d(a_x, a_y, a_z)
Parameters
a_xx component.
a_yy component.
a_zz component.
void chai3d::cVector3d::subr ( const cVector3d a_vector,
cVector3d a_result 
) const
inline

This method computes the subtraction of this vector with a vector passed by argument.
The result is stored in the result vector a_result that is passed by argument.

a_result = this - a_vector
Parameters
a_vectorVector to be subtracted from current one.
a_resultResult of operation.
void chai3d::cVector3d::subr ( const double &  a_x,
const double &  a_y,
const double &  a_z,
cVector3d a_result 
) const
inline

This method computes the subtraction of this vector with a vector passed by argument.
The result is stored in the result vector a_result that is passed by argument.

a_result = this - cVector3d(a_x, a_y, a_z)
Parameters
a_xx component.
a_yy component.
a_zz component.
a_resultResult of operation.
void chai3d::cVector3d::mul ( const double &  a_scalar)
inline

This method computes the multiplication of this vector by a scalar a_scalar passed by argument.
The result is stored in this vector.

this = a_scalar * this
Parameters
a_scalarScalar value.
void chai3d::cVector3d::mul ( const double &  a_scalar0,
const double &  a_scalar1,
const double &  a_scalar2 
)
inline

This method computes the multiplication of each component of this vector by a set of scalars a_scalar0, a_scalar1, and a_scalar2 passed by argument.
The result is stored in this vector.

this(0) = a_scalar0 * this(0)
this(1) = a_scalar1 * this(1)
this(2) = a_scalar2 * this(2)
Parameters
a_scalar0Scalar value for component 0.
a_scalar1Scalar value for component 1.
a_scalar2Scalar value for component 2.
void chai3d::cVector3d::mulr ( const double &  a_scalar,
cVector3d a_result 
) const
inline

This method computes the multiplication of this vector by a scalar a_scalar passed by argument.
The result is stored in the result vector a_result that is passed by argument.

a_result = a_scalar * this
Parameters
a_scalarScalar value.
a_resultResult of operation.
void chai3d::cVector3d::mulr ( const double &  a_scalar0,
const double &  a_scalar1,
const double &  a_scalar2,
cVector3d a_result 
) const
inline

This method computes the multiplication of each component of this vector by a set of scalars a_scalar0, a_scalar1, and a_scalar2 passed by argument.
The result is stored in the result vector a_result that is passed by argument.

a_result(0) = a_scalar0 * this(0)
a_result(1) = a_scalar1 * this(1)
a_result(2) = a_scalar2 * this(2)
Parameters
a_scalar0Scalar value for component 0.
a_scalar1Scalar value for component 1.
a_scalar2Scalar value for component 2.
a_resultResult of operation.
void chai3d::cVector3d::mulElement ( const cVector3d a_vector)
inline

This method computes the element-by-element product between this vector and a vector a_vector passed by argument.
The result is stored in this vector.

Parameters
a_vectorInput vector.
void chai3d::cVector3d::mulElementr ( const cVector3d a_vector,
cVector3d a_result 
) const
inline

This method computes the element-by-element product between this vector and a vector a_vector passed by argument.
The result is stored in the result vector a_result that is passed by argument.

Parameters
a_vectorInput vector.
a_resultResult of operation.
void chai3d::cVector3d::div ( const double &  a_scalar)
inline

This method computes the division of this vector by a scalar a_scalar passed by argument.
The result is stored in this vector.

this = this / a_scalar
Parameters
a_scalarScalar value.
void chai3d::cVector3d::divr ( const double &  a_scalar,
cVector3d a_result 
) const
inline

This method computes the division of this vector by a scalar a_scalar passed by argument.
The result is stored in the result vector a_result that is passed by argument.

a_result = this / a_scalar
Parameters
a_scalarScalar value.
a_resultResult of operation.
void chai3d::cVector3d::negate ( )
inline

This method computes the negated vector of this vector.
The result is stored in this vector.

this = -this
void chai3d::cVector3d::negater ( cVector3d a_result) const
inline

This method computes the negated vector of this vector.
The result is stored in the result vector a_result that is passed by argument.

a_result = -this
Parameters
a_resultResult of operation.
void chai3d::cVector3d::cross ( const cVector3d a_vector)
inline

This method computes the cross product between this vector and an vector a_vector passed by argument.
The result is stored in the current vector.

Parameters
a_vectorInput vector.
void chai3d::cVector3d::crossr ( const cVector3d a_vector,
cVector3d a_result 
) const
inline

This method computes the cross product between this vector and an vector a_vector passed by argument.
The result is stored in the result vector a_result that is passed by argument.

Parameters
a_vectorInput vector.
a_resultResulting cross product.
double chai3d::cVector3d::dot ( const cVector3d a_vector) const
inline

This method computes and returns the dot product between this vector and an vector a_vector passed by argument.

Parameters
a_vectorInput vector.
Returns
Dot product between both vectors.
double chai3d::cVector3d::length ( ) const
inline

This method computes and returns the Euclidean norm of this vector.

Returns
Euclidean norm of this vector.
double chai3d::cVector3d::lengthsq ( ) const
inline

This method computes and returns the squared value of the Euclidean norm of this vector.

Returns
Squared value of the Euclidean norm of this vector.
void chai3d::cVector3d::normalize ( )
inline

This method normalizes this vector to length 1.

WARNING:
The vector should not be equal to (0,0,0), otherwise a division by zero error will occur.

The result of this operation is stored in this vector.

void chai3d::cVector3d::normalizer ( cVector3d a_result) const
inline

This method normalizes this vector to length 1.

WARNING:
The vector should not be equal to (0,0,0), otherwise a division by zero error will occur.
The result is stored in the result vector a_result that is passed by argument.

Parameters
a_resultNormalized vector.
void chai3d::cVector3d::clamp ( const double &  a_maxLength)
inline

This method clamps this vector to a maximum desired length. Vectors that are shorter argument than a_maxLength are not affected.
The result of this operation is stored in this vector.

Parameters
a_maxLengthMaximum length value.
double chai3d::cVector3d::distance ( const cVector3d a_vector) const
inline

This method computes and returns the distance between this point and an point a_vector passed by argument.

Parameters
a_vectorInput point.
Returns
Distance between both points.
double chai3d::cVector3d::distancesq ( const cVector3d a_vector) const
inline

This method computes and returns the squared value distance between this point and an point a_vector passed by argument.

Parameters
a_vectorInput point.
Returns
Squared value distance between both points.
bool chai3d::cVector3d::equals ( const cVector3d a_vector,
const double  a_epsilon = 0.0 
) const
inline

This method tests whether the current vector and external vector a_vector passed as argument are both equal. Two vectors are considered equal if each of their components are distant within an distance epsilon defined by the second argument a_epsilon. By default, epsilon is set to zero.

Parameters
a_vectorInput vector.
a_epsilonTolerance error.
Returns
true if both vectors are equal, false otherwise.
std::string chai3d::cVector3d::str ( const unsigned int  a_precision = 2) const
inline

This method convert this vector into a string. The number of digits after the decimal point are set by argument a_precision.

Parameters
a_precisionNumber of digits.
Returns
Converted vector in string format.
void chai3d::cVector3d::operator/= ( const double &  a_val)
inline
void chai3d::cVector3d::operator*= ( const double &  a_val)
inline
void chai3d::cVector3d::operator+= ( const cVector3d a_input)
inline
void chai3d::cVector3d::operator-= ( const cVector3d a_input)
inline
double& chai3d::cVector3d::operator() ( const int  a_index)
inline
const double& chai3d::cVector3d::operator() ( const int  a_index) const
inline

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