An Implementation of the Marching Cubes Algorithm  1.0
common::t3DVector Class Reference

This class represents a vector in 3D space. More...

#include <3dvector.hpp>

List of all members.

Public Member Functions

 t3DVector ()
 Creates an instance of this class.
 t3DVector (const t3DVector &v)
 Creates an instance of this class from another instance of this class.
 t3DVector (double x, double y, double z)
 Creates an instance of this class and initializes it with a given set of coordinates.
void set_coordinates (const t3DVector &v)
 Changes the coordinates of this vector so that they become equal to the respective coordinates of a given vector.
void set_coordinates (double x, double y, double z)
 Changes the coordinates of this vector.
bool operator== (const t3DVector &v) const
 Verifies whether this vector is equal to a given vector.
bool operator!= (const t3DVector &v) const
 Verifies whether this vector is different from a given vector.
t3DVectoroperator= (const t3DVector &v)
 Assigns a given vector to this vector.
t3DVectoroperator+= (const t3DVector &v)
 Makes this vector equal to itself plus a given vector, and then returns this vector.
t3DVectoroperator-= (const t3DVector &v)
 Makes this vector equal to itself minus a given vector, and then returns this vector.
t3DVectoroperator*= (double alpha)
 Scales this vector by a given constant factor.
t3DVector operator- () const
 Multiplies the coordinates of this vector by -1 and then returns the resulting vector. This vector itself is not changed.
t3DVector operator+ (const t3DVector &v) const
 Returns the vector resulting from adding this vector to a given vector.
t3DVector operator- (const t3DVector &v) const
 Returns the vector resulting from subtracting a given vector from this vector.
t3DVector operator* (double alpha) const
 Returns the vector resulting from scaling this vector by a constant factor.
double operator* (const t3DVector &v) const
 Computes the dot product of this vector and a given vector.
double operator[] (unsigned i) const throw ( ExceptionObject )
 Returns the i-th coordinate of this vetor.
double & operator[] (unsigned i) throw ( ExceptionObject )
double length () const
 Returns the length of this vector.
bool is_null () const
 Returns the logic value true if this vector has lenght zero, and the logic value false otherwise.
t3DVectornegate ()
 Multiplies the coordinates of this vector by -1, and then returns this vector after the coordinate values are changed.
double inner (const t3DVector &v) const
 Computes the dot product of this vector and a given vector.
t3DVectornormalize ()
 Normalizes this vector and then returns a reference to it.
t3DVector cross (const t3DVector &v) const
 Returns a 3D vector corresponding to the cross product of this vector and a given vector.

Public Attributes

double _x
 The first coordinate of the vector.
double _y
 The second coordinate of the vector.
double _z
 The third coordinate of the vector.

Friends

t3DVector operator* (double alpha, const t3DVector &v)
 Scales this vector by a constant factor and returns the vector after scaling.

Detailed Description

This class represents a vector in 3D space.

Definition at line 57 of file 3dvector.hpp.


Constructor & Destructor Documentation

common::t3DVector::t3DVector ( const t3DVector v) [inline]

Creates an instance of this class from another instance of this class.

Parameters:
vA given 3D vector to be cloned.

Definition at line 86 of file 3dvector.hpp.

                                    : 
      _x( v._x ) , 
      _y( v._y ) , 
      _z( v._z ) 
    {
    }
common::t3DVector::t3DVector ( double  x,
double  y,
double  z 
) [inline]

Creates an instance of this class and initializes it with a given set of coordinates.

Parameters:
xThe X coordinate of the vector.
yThe Y coordinate of the vector.
zThe Z coordinate of the vector.

Definition at line 104 of file 3dvector.hpp.

References set_coordinates().

    {
      this->set_coordinates( x , y , z ) ;
    }

Member Function Documentation

t3DVector common::t3DVector::cross ( const t3DVector v) const [inline]

Returns a 3D vector corresponding to the cross product of this vector and a given vector.

Parameters:
vA vector in 3D space.
Returns:
A 3D vector corresponding to the cross product of this vector and a given vector.

Definition at line 525 of file 3dvector.hpp.

References _x, _y, _z, and t3DVector().

    {
      return t3DVector(
                       _y * v._z - _z * v._y ,
                       _z * v._x - _x * v._z ,
                       _x * v._y - _y * v._x
                      ) ;
    }
double common::t3DVector::inner ( const t3DVector v) const [inline]

Computes the dot product of this vector and a given vector.

Parameters:
vA vector in 3D space.
Returns:
The dot product of this vector and a given vector.

Definition at line 487 of file 3dvector.hpp.

References operator*().

    {
      return this->operator*( v ) ;
    }
bool common::t3DVector::is_null ( ) const [inline]

Returns the logic value true if this vector has lenght zero, and the logic value false otherwise.

Returns:
The logic value true if this vector has lenght zero, and the logic value false otherwise.

Definition at line 452 of file 3dvector.hpp.

References _x, _y, and _z.

    {
      return is_zero( _x ) && is_zero( _y ) && is_zero( _z ) ;
    }
double common::t3DVector::length ( ) const [inline]

Returns the length of this vector.

Returns:
The length of this vector.

Definition at line 437 of file 3dvector.hpp.

References _x, _y, and _z.

Referenced by normalize().

    {
      return sqrt( sqr( _x ) + sqr( _y ) + sqr( _z ) ) ;
    }

Multiplies the coordinates of this vector by -1, and then returns this vector after the coordinate values are changed.

Returns:
This vector after negating its coordinate values.

Definition at line 467 of file 3dvector.hpp.

References _x, _y, and _z.

    {
      _x = -_x ;
      _y = -_y ;
      _z = -_z ;
      
      return *this ;
    }

Normalizes this vector and then returns a reference to it.

Returns:
A reference to this vector after normalization.

Definition at line 501 of file 3dvector.hpp.

References _x, _y, _z, and length().

    {
      double inv_norm = INVERSE( this->length() ) ;

      _x *= inv_norm ;
      _y *= inv_norm ;
      _z *= inv_norm ;

      return *this ;
    }
bool common::t3DVector::operator!= ( const t3DVector v) const [inline]

Verifies whether this vector is different from a given vector.

Returns:
The logic value false if this vector has the same coordinates of a given vector. Otherwise, the logic value true is returned.

Definition at line 174 of file 3dvector.hpp.

    {
      return *this == v ;
    }
t3DVector common::t3DVector::operator* ( double  alpha) const [inline]

Returns the vector resulting from scaling this vector by a constant factor.

Parameters:
alphaA scalar.
Returns:
The vector resulting from scaling this vector by a constant factor.

Definition at line 325 of file 3dvector.hpp.

References _x, _y, _z, and t3DVector().

Referenced by inner().

    {
      return t3DVector(
                        _x * alpha , 
                        _y * alpha , 
                        _z * alpha
                      ) ;
    }
double common::t3DVector::operator* ( const t3DVector v) const [inline]

Computes the dot product of this vector and a given vector.

Parameters:
vA vector in 3D space.
Returns:
The dot product of this vector and a given vector.

Definition at line 359 of file 3dvector.hpp.

References _x, _y, and _z.

    {
      return _x * v._x + _y * v._y + _z * v._z ;
    }
t3DVector & common::t3DVector::operator*= ( double  alpha) [inline]

Scales this vector by a given constant factor.

Parameters:
alphaA scalar.
Returns:
This vector after being scaled.

Definition at line 246 of file 3dvector.hpp.

References _x, _y, and _z.

    {
      _x *= alpha ;
      _y *= alpha ;
      _z *= alpha ;
      
      return *this ;
    }
t3DVector common::t3DVector::operator+ ( const t3DVector v) const [inline]

Returns the vector resulting from adding this vector to a given vector.

Parameters:
vA vector in 3D space.
Returns:
The vector resulting from adding this vector to a given vector.

Definition at line 283 of file 3dvector.hpp.

References _x, _y, _z, and t3DVector().

    {
      return t3DVector(
                        _x + v._x , 
                        _y + v._y , 
                        _z + v._z
                      ) ;
    }
t3DVector & common::t3DVector::operator+= ( const t3DVector v) [inline]

Makes this vector equal to itself plus a given vector, and then returns this vector.

Parameters:
vA vector in 3D space.
Returns:
This vector after addition.

Definition at line 207 of file 3dvector.hpp.

References _x, _y, and _z.

    {
      _x += v._x ;
      _y += v._y ;
      _z += v._z ;
      
      return *this ;
    }
t3DVector common::t3DVector::operator- ( ) const [inline]

Multiplies the coordinates of this vector by -1 and then returns the resulting vector. This vector itself is not changed.

Returns:
A vector in 3D corresponding to minus one times this vector.

Definition at line 266 of file 3dvector.hpp.

References _x, _y, _z, and t3DVector().

    {
      return t3DVector( -_x , -_y , -_z ) ;
    }
t3DVector common::t3DVector::operator- ( const t3DVector v) const [inline]

Returns the vector resulting from subtracting a given vector from this vector.

Parameters:
vA vector in 3D space.
Returns:
The vector resulting subtracting a given vector from this vector.

Definition at line 304 of file 3dvector.hpp.

References _x, _y, _z, and t3DVector().

    {
      return t3DVector(
                        _x - v._x , 
                        _y - v._y , 
                        _z - v._z
                      ) ;
    }
t3DVector & common::t3DVector::operator-= ( const t3DVector v) [inline]

Makes this vector equal to itself minus a given vector, and then returns this vector.

Parameters:
vA vector in 3D space.
Returns:
This vector after subtraction.

Definition at line 227 of file 3dvector.hpp.

References _x, _y, and _z.

    {
      _x -= v._x ;
      _y -= v._y ;
      _z -= v._z ;
      
      return *this;
    }
t3DVector & common::t3DVector::operator= ( const t3DVector v) [inline]

Assigns a given vector to this vector.

Parameters:
vA vector in 3D space.

Definition at line 187 of file 3dvector.hpp.

References _x, _y, and _z.

    {
      _x = v._x ;
      _y = v._y ;
      _z = v._z ;
      
      return *this ;
    }
bool common::t3DVector::operator== ( const t3DVector v) const [inline]

Verifies whether this vector is equal to a given vector.

Returns:
The logic value true if this vector has the same coordinates of a given vector. Otherwise, the logic value false is returned.

Definition at line 156 of file 3dvector.hpp.

References _x, _y, and _z.

    {
      return is_equal( _x , v._x ) && 
             is_equal( _y , v._y ) &&
             is_equal( _z , v._z ) ;
    }
double & common::t3DVector::operator[] ( unsigned  i) const throw ( ExceptionObject ) [inline]

Returns the i-th coordinate of this vetor.

Returns a reference to the i-th coordinate of this vetor.

Parameters:
iThe index of a vector coordinate.
Returns:
The i-th coordinate of this vector.
Parameters:
iThe index of a vector coordinate.
Returns:
A reference to the i-th coordinate of this vector.

Definition at line 374 of file 3dvector.hpp.

References _x, _y, and _z.

    {
      if ( i > 2 ) {
        std::stringstream ss (
                              std::stringstream::in | 
                              std::stringstream::out
                             ) ;
        ss << "Array index is out of range" ;
        throw ExceptionObject( __FILE__ , __LINE__ , ss.str() ) ;  
      }


      if ( i == 0 ) {
        return _x ;
      }
      else if ( i == 1 ) {
        return _y ;
      }

      return _z ;
    }
void common::t3DVector::set_coordinates ( const t3DVector v) [inline]

Changes the coordinates of this vector so that they become equal to the respective coordinates of a given vector.

Parameters:
vA vector in 3D space.

Definition at line 122 of file 3dvector.hpp.

References _x, _y, and _z.

Referenced by t3DVector().

    {
      _x = v._x ;
      _y = v._y ;
      _z = v._z ;
    }
void common::t3DVector::set_coordinates ( double  x,
double  y,
double  z 
) [inline]

Changes the coordinates of this vector.

Parameters:
xThe new value of the X coordinate.
yThe new value of the Y coordinate.
zThe new value of the Z coordinate.

Definition at line 139 of file 3dvector.hpp.

References _x, _y, and _z.

    {
      _x = x ;
      _y = y ;
      _z = z ;
    }

Friends And Related Function Documentation

t3DVector operator* ( double  alpha,
const t3DVector v 
) [friend]

Scales this vector by a constant factor and returns the vector after scaling.

Parameters:
alphaA scalar.
vA vector in 3D space.
Returns:
This vector after scaling.

Definition at line 559 of file 3dvector.hpp.

  {
    return v * alpha ;
  }

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