Vector3 Class Reference

#include <Vector3.h>

List of all members.


Detailed Description

This class defines operations for 3 dimensional vectors.

Definition at line 25 of file Vector3.h.

Public Member Functions

 Vector3 (void)
 Creates empty vector of zeros.
 Vector3 (double x, double y)
 Creates new vector.
 Vector3 (double x, double y, double z)
 Vector3 (const Vector3 &o)
bool operator== (const Vector3 &rhs) const
 Equal operator.
bool operator!= (const Vector3 &rhs) const
const Vector3operator= (const Vector3 &rhs)
const Vector3operator+= (const Vector3 &rhs)
const Vector3operator-= (const Vector3 &rhs)
const Vector3operator *= (const double &rhs)
const Vector3operator/= (const double &rhs)
Vector3 operator+ (const Vector3 &rhs) const
Vector3 operator- (const Vector3 &rhs) const
double dot (const Vector3 &rhs) const
 Dot product of vectors.
Vector3 operator * (const double &rhs) const
Vector3 operator/ (const double &rhs) const
double & operator[] (int i)
 Access operator, first element has index zero.
Vector3 crossProduct (const Vector3 &rhs) const
 Cross product of 3x1 vectors.
double operator[] (int i) const
 Access operator, first element has index zero.
double x () const
double & x ()
double y () const
double & y ()
double z () const
double & z ()
double abs () const
 Absolute value of the vector.
Vector3 norm () const
 Returns normalized vector.
void normalize ()
 Normalize current vector.
void negate ()
 Negate each element of the vector.
void print (std::ostream &out, char *name) const

Static Public Member Functions

static Vector3 e1 ()
 Returns unit vector in x direction.
static Vector3 e2 ()
 Returns unit vector in y direction.
static Vector3 e3 ()
 Returns unit vector in z direction.
static Vector3 ones ()
 Returns 3x1 vector of all ones.

Private Member Functions

void copy (const Vector3 &o)
const Vector3operator *= (const Vector3 &rhs)

Private Attributes

double vec [vDim]

Friends

std::ostream & operator<< (std::ostream &out, const Vector3 &m)
std::istream & operator>> (std::istream &in, Vector3 &m)


Constructor & Destructor Documentation

Vector3::Vector3 void   )  [inline]
 

Creates empty vector of zeros.

Definition at line 55 of file Vector3.h.

00055                 {
00056       for (int i = 0; i < vDim; i++)
00057           vec[i] = 0;
00058    }

Vector3::Vector3 double  x,
double  y
[inline]
 

Creates new vector.

Parameters:
x New x component of the vector
y New y component of the vector

Definition at line 64 of file Vector3.h.

00064                               {
00065       vec[0] = x; vec[1] = y; vec[2] = 0;
00066    }

Vector3::Vector3 double  x,
double  y,
double  z
[inline]
 

Definition at line 68 of file Vector3.h.

00068                                         {
00069       vec[0] = x; vec[1] = y; vec[2] = z;
00070    }

Vector3::Vector3 const Vector3 o  )  [inline]
 

Definition at line 72 of file Vector3.h.

00072                              {
00073       copy(o);
00074    }


Member Function Documentation

double Vector3::abs  )  const [inline]
 

Absolute value of the vector.

Definition at line 199 of file Vector3.h.

00199                        {
00200       double sum = 0;
00201       for (int i = 0; i < vDim; i++)
00202           sum += vec[i]*vec[i];
00203       return sqrt(sum);
00204    }

void Vector3::copy const Vector3 o  )  [inline, private]
 

Definition at line 31 of file Vector3.h.

00031                                 {
00032       for (int i = 0; i < vDim; i++)
00033           vec[i] = o.vec[i];
00034    }

Vector3 Vector3::crossProduct const Vector3 rhs  )  const [inline]
 

Cross product of 3x1 vectors.

Definition at line 169 of file Vector3.h.

00169                                                  {
00170       Vector3 tmp;
00171       tmp[0] = vec[1]*rhs[2] - vec[2]*rhs[1];
00172       tmp[1] = vec[2]*rhs[0] - vec[0]*rhs[2];
00173       tmp[2] = vec[0]*rhs[1] - vec[1]*rhs[0];
00174       return tmp;
00175    }

double Vector3::dot const Vector3 rhs  )  const [inline]
 

Dot product of vectors.

Definition at line 137 of file Vector3.h.

00137                                         {
00138       Vector3 tmp(*this);
00139       tmp *= rhs;
00140       double sum = 0;
00141       for (int i = 0; i < vDim; i++)
00142           sum += tmp.vec[i];
00143       return sum;
00144    }

static Vector3 Vector3::e1  )  [inline, static]
 

Returns unit vector in x direction.

Definition at line 46 of file Vector3.h.

00046 {return Vector3(1, 0, 0);}

static Vector3 Vector3::e2  )  [inline, static]
 

Returns unit vector in y direction.

Definition at line 48 of file Vector3.h.

00048 {return Vector3(0, 1, 0);}

static Vector3 Vector3::e3  )  [inline, static]
 

Returns unit vector in z direction.

Definition at line 50 of file Vector3.h.

00050 {return Vector3(0, 0, 1);}

void Vector3::negate  )  [inline]
 

Negate each element of the vector.

Definition at line 230 of file Vector3.h.

00230                   {
00231       vec[0] = -vec[0];
00232       vec[1] = -vec[1];
00233       vec[2] = -vec[2];
00234    }

Vector3 Vector3::norm  )  const [inline]
 

Returns normalized vector.

Returns:
nomalized vector in same direction

Definition at line 210 of file Vector3.h.

00210                         {
00211       Vector3 norm;
00212       double length = abs();
00213       for (int i = 0; i < vDim; i++)
00214           norm[i] = vec[i]/length;
00215       return norm;
00216    }

void Vector3::normalize  )  [inline]
 

Normalize current vector.

Definition at line 221 of file Vector3.h.

00221                    {
00222       double length = abs();
00223       for (int i = 0; i < vDim; i++)
00224           vec[i] = vec[i]/length;
00225    }

static Vector3 Vector3::ones  )  [inline, static]
 

Returns 3x1 vector of all ones.

Definition at line 52 of file Vector3.h.

00052 {return Vector3(1, 1, 1);}

Vector3 Vector3::operator * const double &  rhs  )  const [inline]
 

Definition at line 146 of file Vector3.h.

00146                                               {
00147       Vector3 tmp(*this);
00148       tmp *= rhs;
00149       return tmp;
00150    }

const Vector3& Vector3::operator *= const double &  rhs  )  [inline]
 

Definition at line 108 of file Vector3.h.

00108                                                {
00109       for (int i = 0; i < vDim; i++)
00110           vec[i] = vec[i]*rhs;               
00111       return *this;
00112    }

const Vector3& Vector3::operator *= const Vector3 rhs  )  [inline, private]
 

Definition at line 36 of file Vector3.h.

00036                                                 {
00037       for (int i = 0; i < vDim; i++)
00038           vec[i] = vec[i]*rhs.vec[i];                 
00039       return *this;
00040    }

bool Vector3::operator!= const Vector3 rhs  )  const [inline]
 

Definition at line 85 of file Vector3.h.

00085                                             {
00086       return (!(*this == rhs));
00087    }

Vector3 Vector3::operator+ const Vector3 rhs  )  const [inline]
 

Definition at line 121 of file Vector3.h.

00121                                                {
00122       Vector3 tmp(*this);
00123       tmp += rhs;
00124       return tmp;
00125    }

const Vector3& Vector3::operator+= const Vector3 rhs  )  [inline]
 

Definition at line 95 of file Vector3.h.

00095                                                 {
00096       for (int i = 0; i < vDim; i++)
00097           vec[i] = vec[i]+rhs.vec[i];                 
00098       return *this;
00099    }

Vector3 Vector3::operator- const Vector3 rhs  )  const [inline]
 

Definition at line 128 of file Vector3.h.

00128                                                {
00129       Vector3 tmp(*this);
00130       tmp -= rhs;
00131       return tmp;
00132    }     

const Vector3& Vector3::operator-= const Vector3 rhs  )  [inline]
 

Definition at line 101 of file Vector3.h.

00101                                                 {
00102       for (int i = 0; i < vDim; i++)
00103           vec[i] = vec[i]-rhs.vec[i];                 
00104       return *this;
00105    }

Vector3 Vector3::operator/ const double &  rhs  )  const [inline]
 

Definition at line 152 of file Vector3.h.

00152                                               {
00153       Vector3 tmp(*this);
00154       tmp /= rhs;
00155       return tmp;
00156    }

const Vector3& Vector3::operator/= const double &  rhs  )  [inline]
 

Definition at line 114 of file Vector3.h.

00114                                                {
00115       for (int i = 0; i < vDim; i++)
00116           vec[i] = vec[i]/rhs;               
00117       return *this;
00118    }

const Vector3& Vector3::operator= const Vector3 rhs  )  [inline]
 

Definition at line 89 of file Vector3.h.

00089                                                {
00090       if (this != &rhs)
00091           copy(rhs);
00092       return *this;
00093    }

bool Vector3::operator== const Vector3 rhs  )  const [inline]
 

Equal operator.

Returns:
Vectors are equal when each component differs less then by 1.e-14

Definition at line 79 of file Vector3.h.

00079                                             {
00080       return (fabs(vec[0] - rhs.vec[0]) < 1.e-14 && 
00081           fabs(vec[1] - rhs.vec[1]) <  1.e-14 && 
00082           fabs(vec[2] - rhs.vec[2]) <  1.e-14);
00083    }

double Vector3::operator[] int  i  )  const [inline]
 

Access operator, first element has index zero.

Definition at line 180 of file Vector3.h.

00180                                   {
00181       if (i >= vDim || i < 0){
00182           std::cerr << "Out of bounds vector accessing: [" << i << "]" << std::endl;
00183           return 0;
00184       }
00185       else
00186           return vec[i];
00187    }

double& Vector3::operator[] int  i  )  [inline]
 

Access operator, first element has index zero.

Definition at line 162 of file Vector3.h.

00162                               {
00163       return vec[i];
00164    }

void Vector3::print std::ostream &  out,
char *  name
const [inline]
 

Definition at line 237 of file Vector3.h.

00237                                                  { 
00238       for (int i = 0; i < vDim; i++)
00239           out << name << "(" << (i+1) << ")= " << vec[i] << "; ";
00240       out << std::endl;
00241    } 

double& Vector3::x  )  [inline]
 

Definition at line 190 of file Vector3.h.

00190 {return vec[0];}

double Vector3::x  )  const [inline]
 

Definition at line 189 of file Vector3.h.

00189 {return vec[0];}

double& Vector3::y  )  [inline]
 

Definition at line 192 of file Vector3.h.

00192 {return vec[1];}

double Vector3::y  )  const [inline]
 

Definition at line 191 of file Vector3.h.

00191 {return vec[1];}

double& Vector3::z  )  [inline]
 

Definition at line 194 of file Vector3.h.

00194 {return vec[2];}

double Vector3::z  )  const [inline]
 

Definition at line 193 of file Vector3.h.

00193 {return vec[2];}


Friends And Related Function Documentation

std::ostream& operator<< std::ostream &  out,
const Vector3 m
[friend]
 

Definition at line 243 of file Vector3.h.

00243                                                                     { 
00244       out << m.vec[0];
00245       for (int i = 1; i < vDim; i++)
00246           out << "  " << m.vec[i];
00247       return out; 
00248    } 

std::istream& operator>> std::istream &  in,
Vector3 m
[friend]
 

Definition at line 251 of file Vector3.h.

00251                                                               { 
00252       for (int i = 0; i < vDim; i++)
00253           in >> m.vec[i];
00254       return in; 
00255    } 


Member Data Documentation

double Vector3::vec[vDim] [private]
 

Definition at line 29 of file Vector3.h.


The documentation for this class was generated from the following file:
Generated on Sat Jun 3 13:33:43 2006 for CirclePatterns by  doxygen 1.4.5