math/Vector4.h

Go to the documentation of this file.
00001 #ifndef Vector4_h
00002 #define Vector4_h 1
00003 
00004 #include <assert.h>
00005 #include <iostream>
00006 #include "math2.h"
00007 
00008 
00009 class Vector4 
00010 {
00011 
00012   public:
00013     //## Constructors (specified)
00014       //## Operation: Vector4%922649209
00015       Vector4 ();
00016 
00017       //## Operation: Vector4%922649210
00018       Vector4 (const Vector4& right);
00019 
00020       //## Operation: Vector4%925235856
00021       Vector4 (const double  x, const double  y, const double  z);
00022 
00023     //## Destructor (generated)
00024       ~Vector4();
00025 
00026 
00027     //## Other Operations (specified)
00028       //## Operation: operator[]%922649204
00029       double& operator [] (const unsigned int index);
00030 
00031       //## Operation: operator+%922649205
00032       Vector4 operator + (const Vector4& right) const;
00033 
00034       //## Operation: operator-%922649206
00035       Vector4 operator - (const Vector4& right) const;
00036 
00037       Vector4& operator -= (const Vector4& right);
00038 
00039       //## Operation: operator*%922649207
00040       Vector4 operator * (const double right) const;
00041 
00042       //## Operation: operator*%922649207
00043       Vector4 operator / (const double right) const;
00044 
00045       //## Operation: operator[]%922649208
00046       const double operator [] (const unsigned int index) const;
00047 
00048       //## Operation: Magnitude%925235851
00049       //        returns the length of the vector
00050       double Magnitude () const;
00051 
00052       //## Operation: MagSquared%925235852
00053       //        this returns the square of the magnitude of the vector
00054       double MagSquared () const;
00055 
00056       //## Operation: Dot%926709626
00057       double Dot (const Vector4& right) const;
00058 
00059       //## Operation: Cross%926806998
00060       Vector4 Cross (const Vector4& right) const;
00061 
00062       //## Operation: Projection%926806999
00063       Vector4 Projection (const Vector4& right) const;
00064 
00065       //## Operation: ProjectionMag%926807000
00066       double ProjectionMag (const Vector4& right) const;
00067 
00068           //reflects this vector about a normal
00069           void Reflect( const Vector4& normal );
00070 
00071       //## Operation: operator==%926807001
00072       bool operator == (const Vector4& right) const;
00073 
00074           bool operator< ( const Vector4& right ) const; 
00075 
00076       //## Operation: Normalize%927307381
00077       void Normalize ();
00078 
00079           // Compares if two vectors are equal to within a given Tolerance.
00080           bool Compare( const Vector4& right, const double& tol) const;
00081 
00082 
00083     // Additional Public Declarations
00084       //## begin Vector4%36FEE75503CA.public preserve=yes
00085           bool operator !=( const Vector4& right ) const;
00086           Vector4& operator +=( const Vector4& right );
00087           Vector4& operator *=( const double right );
00088       Vector4& operator /=( const double right );
00089           Vector4 operator -() const;
00090       //## end Vector4%36FEE75503CA.public
00091 
00092   protected:
00093       double elements[ 3 ];
00094 
00095   private:
00096 
00097   private: //## implementation
00098 
00099 };
00100 
00101 //std::ostream & operator<<( std::ostream &os, const Vector4& v );
00102 
00103 inline double& Vector4::operator [] (const unsigned int index)
00104 {
00105     IJG_Assert( index < 3 );
00106     IJG_Assert( index >= 0 );
00107         return elements[ index ];
00108 }
00109 
00110 inline const double Vector4::operator [] (const unsigned int index) const
00111 {
00112     IJG_Assert( index < 3 );
00113     IJG_Assert( index >= 0 );
00114         return elements[ index ];
00115 }
00116 
00117 //=============================================================================
00118 // operator +=
00119 //
00120 // Description: in place addition operator
00121 //=============================================================================
00122 inline Vector4& Vector4::operator +=( const Vector4& right )
00123 {
00124         elements[ 0 ] += right.elements[ 0 ];
00125         elements[ 1 ] += right.elements[ 1 ];
00126         elements[ 2 ] += right.elements[ 2 ];
00127         return *this;
00128 }
00129 
00130 //=============================================================================
00131 // Constructor
00132 //
00133 // Description: copies x,y,z into the vector
00134 //=============================================================================
00135 inline Vector4::Vector4 (const double  x, const double  y, const double  z)
00136 {
00137         elements[ 0 ] = x ;
00138         elements[ 1 ] = y ;
00139         elements[ 2 ] = z ;
00140 }
00141 
00142 //=============================================================================
00143 // Destructor
00144 //
00145 // Description: does nothign
00146 //=============================================================================
00147 inline Vector4::~Vector4()
00148 {
00149 }
00150 
00151 
00152 std::ostream & operator<<( std::ostream &os, const Vector4& v ) ;
00153 std::istream & operator>>( std::istream &is, Vector4& v ) ;
00154 
00155 //=============================================================================
00156 // Verify
00157 //
00158 // Description: verifies that the vector is within valid ranges
00159 //=============================================================================
00160 #ifdef _DEBUG
00161 inline void Verify( const Vector4& v )
00162 {
00163         assert( Between( v[ 0 ], -10000.0, 10000.0 ) ); //+-10000 is rather arbitrary
00164         assert( Between( v[ 1 ], -10000.0, 10000.0 ) ); //+-10000 is rather arbitrary
00165         assert( Between( v[ 2 ], -10000.0, 10000.0 ) ); //+-10000 is rather arbitrary
00166 }
00167 #else
00168 inline void Verify( const Vector4& v )
00169 {
00170         //nothing
00171 }
00172 #endif
00173 
00174 #endif

Generated on Sat Apr 1 21:30:38 2006 for Motion Planning Kernel by  doxygen 1.4.6-NO