vec Class Reference

double-precision 3D vector class More...

#include <vec.hpp>

List of all members.

Public Member Functions

 vec ()
 vec (const vec &)
 vec (const double &, const double &, const double &)
 ~vec ()
double & operator() (const int &)
double operator() (const int &) const
void normalize ()
vec operator+ (void)
vec operator- (void)
vecoperator= (const vec &)
vecoperator+= (const vec &)
vecoperator-= (const vec &)
vecoperator/= (const vec &)
vecoperator *= (const double &)
vecoperator/= (const double &)

Public Attributes

double x
 $ V_0 $ component
double y
 $ V_1 $ component
double z
 $ V_2 $ component

Friends

std::ostream & operator<< (std::ostream &, const vec &)
double abs (const vec &)
double norm (const vec &)
vec normal (const vec &)
vec rotate (const vec &, const quat &)
vec orbit (const vec &, const quat &)
quat vr2q (const vec &, const double &)
quat vt2q (const vec &, const double &)
void swap (vec &, vec &)
vec operator * (const vec &, const mat &)
vec operator+ (const vec &, const vec &)
vec operator- (const vec &, const vec &)
mat operator * (const vec &, const vec &)
double operator% (const vec &, const vec &)
vec operator/ (const vec &, const vec &)
vec operator * (const vec &, const double &)
vec operator/ (const vec &, const double &)
vec operator * (const double &, const vec &)


Detailed Description

double-precision 3D vector class

Definition at line 3 of file vec.hpp.


Constructor & Destructor Documentation

vec::vec  )  [inline]
 

vec constructor without arguments

Definition at line 3 of file vec-constructor.hpp.

Referenced by operator-().

00004 {
00005   ;
00006 }

vec::vec const vec v  )  [inline]
 

vec copy constructor

Definition at line 14 of file vec-constructor.hpp.

00015   : x(v.x), y(v.y), z(v.z)
00016 {
00017   ;
00018 }

vec::vec const double &  _x,
const double &  _y,
const double &  _z
[inline]
 

vec constructor to build from three components

Definition at line 22 of file vec-constructor.hpp.

00023   : x(_x), y(_y), z(_z)
00024 {
00025   ;
00026 }

vec::~vec  )  [inline]
 

vec destructor

Definition at line 34 of file vec-constructor.hpp.

00035 {
00036   ;
00037 }


Member Function Documentation

double & vec::operator() const int &  i  )  [inline]
 

operator() for non-const object

Definition at line 3 of file vec-io.hpp.

References x, y, and z.

00004 {
00005   switch( i ){
00006   case 0: return x;
00007   case 1: return y;
00008   case 2: return z;
00009   default:
00010     std::cerr << "[ERROR] vec::operator()(const int&)" << std::endl
00011               << "The required component was not 0, 1, or 2." << std::endl
00012               << "Your input was (" << i << ")." << std::endl;
00013     std::exit(1);
00014   }
00015 }

double vec::operator() const int &  i  )  const [inline]
 

operator() for const object

Definition at line 19 of file vec-io.hpp.

References x, y, and z.

00020 {
00021   switch( i ){
00022   case 0: return x;
00023   case 1: return y;
00024   case 2: return z;
00025   default:
00026     std::cerr << "[ERROR] vec::operator()(const int&) const" << std::endl
00027               << "The required component was not 0, 1, or 2." << std::endl
00028               << "Your input was (" << i << ")." << std::endl;
00029     std::exit(1);
00030   }
00031 }

void vec::normalize  )  [inline]
 

normalize itself

Definition at line 3 of file vec-calc.hpp.

References abs, x, y, and z.

00004 {
00005   double myabs(abs(*this));
00006   x /=myabs;
00007   y /=myabs;
00008   z /=myabs;
00009 }

vec vec::operator+ void   )  [inline]
 

Definition at line 2 of file vec-unary.hpp.

00003 {
00004   return( *this );
00005 }

vec vec::operator- void   )  [inline]
 

Definition at line 8 of file vec-unary.hpp.

References vec(), x, y, and z.

00009 {
00010   return vec(-x, -y, -z);
00011 }

vec & vec::operator= const vec v  )  [inline]
 

vec=vec operator

Definition at line 3 of file vec-vec.hpp.

References x, y, and z.

00004 {
00005   x =v.x;
00006   y =v.y;
00007   z =v.z;
00008   return *this;
00009 }

vec & vec::operator+= const vec v  )  [inline]
 

vec+=vec operator

Definition at line 17 of file vec-vec.hpp.

References x, y, and z.

00018 {
00019   x +=v.x;
00020   y +=v.y;
00021   z +=v.z;
00022   return *this;
00023 }

vec & vec::operator-= const vec v  )  [inline]
 

vec-=vec operator

Definition at line 27 of file vec-vec.hpp.

References x, y, and z.

00028 {
00029   x -=v.x;
00030   y -=v.y;
00031   z -=v.z;
00032   return *this;
00033 }

vec & vec::operator/= const vec v  )  [inline]
 

vec/=vec operator (outer product)

Definition at line 37 of file vec-vec.hpp.

00038 {
00039   (*this) =(*this)/v;
00040   return *this;
00041 }

vec & vec::operator *= const double &  d  )  [inline]
 

vec*=double operator

Definition at line 3 of file vec-double.hpp.

References x, y, and z.

00004 {
00005   x *=d;
00006   y *=d;
00007   z *=d;
00008   return *this;
00009 }

vec & vec::operator/= const double &  d  )  [inline]
 

vec/=double operator

Definition at line 13 of file vec-double.hpp.

References x, y, and z.

00014 {
00015   x /=d;
00016   y /=d;
00017   z /=d;
00018   return *this;
00019 }


Friends And Related Function Documentation

std::ostream& operator<< std::ostream &  s,
const vec v
[friend]
 

Definition at line 38 of file vec-io.hpp.

00039 {
00040   s << "{ "<< v.x << "; " << v.y << "; " << v.z << " }";
00041   return s;
00042 }

double abs const vec v  )  [friend]
 

return abs

Definition at line 17 of file vec-calc.hpp.

Referenced by normalize().

00018 {
00019 #ifdef  QVM_DEBUG
00020   double result(std::sqrt(v.x*v.x +v.y*v.y +v.z*v.z));
00021   if( result < DBL_MIN || !finite(result) ){
00022     std::cerr << "[WARNING] abs(const vec&) "
00023               << "The abs is numerically ZERO." << std::endl;
00024   }
00025 #endif//QVM_DEBUG
00026   return std::sqrt(v.x*v.x +v.y*v.y +v.z*v.z) +DBL_MIN;
00027 }

double norm const vec v  )  [friend]
 

return norm

Definition at line 31 of file vec-calc.hpp.

00032 {
00033 #ifdef  QVM_DEBUG
00034   double result(v.x*v.x +v.y*v.y +v.z*v.z);
00035   if( result < DBL_MIN || !finite(result) ){
00036     std::cerr << "[WARNING] norm(const vec&) "
00037               << "The norm is numerically ZERO." << std::endl;
00038   }
00039 #endif//QVM_DEBUG
00040   return v.x*v.x +v.y*v.y +v.z*v.z;
00041 }

vec normal const vec v  )  [friend]
 

return the normalized vec

Definition at line 45 of file vec-calc.hpp.

00046 {
00047   double abs_v(abs(v));
00048   return vec( v.x/abs_v, v.y/abs_v, v.z/abs_v );
00049 }

vec rotate const vec v,
const quat q
[friend]
 

Definition at line 53 of file vec-calc.hpp.

00054 {
00055   //return im( conj(q)*vr2q(v,0.)*q );
00056   return im( q*vr2q(v,0.)*conj(q) );
00057 }

vec orbit const vec v,
const quat q
[friend]
 

Definition at line 61 of file vec-calc.hpp.

00062 {
00063   return im( q*vr2q(v,0.)*conj(q) );
00064 }

quat vr2q const vec v,
const double &  _r
[friend]
 

return quat from vec and real

Definition at line 3 of file vec-misc.hpp.

00004 {
00005   return quat(v.x, v.y, v.z, _r);
00006 }

quat vt2q const vec v,
const double &  theta
[friend]
 

return quat from vec and angle

Definition at line 10 of file vec-misc.hpp.

00011 {
00012   vec n(normal(v));
00013   double sin_theta_half(std::sin(0.5*theta));
00014   return quat( n.x*sin_theta_half, n.y*sin_theta_half, n.z*sin_theta_half,
00015                std::cos(0.5*theta) );
00016 }

void swap vec v1,
vec v2
[friend]
 

swap two vecs

Definition at line 24 of file vec-misc.hpp.

00025 {
00026   vec _v1(v1);
00027   v1 = v2;
00028   v2 =_v1;
00029 }

vec operator * const vec v,
const mat m
[friend]
 

vec * mat

Definition at line 3 of file vec-mat.hpp.

00004 {
00005   return vec( v.x*m.xx +v.y*m.yx +v.x*m.zx,
00006               v.x*m.xy +v.y*m.yy +v.x*m.zy,
00007               v.x*m.xz +v.y*m.yz +v.x*m.zz );
00008 }

vec operator+ const vec v1,
const vec v2
[friend]
 

vec+vec operator

Definition at line 49 of file vec-vec.hpp.

00050 {
00051   return vec(v1.x+v2.x, v1.y+v2.y, v1.z+v2.z);
00052 }

vec operator- const vec v1,
const vec v2
[friend]
 

vec-vec operator

Definition at line 56 of file vec-vec.hpp.

00057 {
00058   return vec(v1.x-v2.x, v1.y-v2.y, v1.z-v2.z);
00059 }

mat operator * const vec cv,
const vec rv
[friend]
 

vec*vec operator

Definition at line 63 of file vec-vec.hpp.

00064 {
00065   return mat( cv.x*rv.x, cv.x*rv.y, cv.x*rv.z,
00066               cv.y*rv.x, cv.y*rv.y, cv.y*rv.z,
00067               cv.z*rv.x, cv.z*rv.y, cv.z*rv.z );
00068 }

double operator% const vec v1,
const vec v2
[friend]
 

vec%vec operator (inner product)

Definition at line 72 of file vec-vec.hpp.

00073 {
00074   return v1.x*v2.x +v1.y*v2.y +v1.z*v2.z;
00075 }

vec operator/ const vec v1,
const vec v2
[friend]
 

vec/vec operator (outer product)

Definition at line 79 of file vec-vec.hpp.

00080 {
00081   return vec( v1.y*v2.z -v2.y*v1.z,
00082               v1.z*v2.x -v2.z*v1.x,
00083               v1.x*v2.y -v2.x*v1.y );
00084 }

vec operator * const vec v,
const double &  d
[friend]
 

vec*double operator

Definition at line 27 of file vec-double.hpp.

00028 {
00029   return vec( v.x*d, v.y*d, v.z*d );
00030 }

vec operator/ const vec v,
const double &  d
[friend]
 

vec/double operator

Definition at line 34 of file vec-double.hpp.

00035 {
00036   return vec( v.x/d, v.y/d, v.z/d );
00037 }

vec operator * const double &  d,
const vec v
[friend]
 

double*vec operator

Definition at line 3 of file double-vec.hpp.

00004 {
00005   return vec( d*v.x, d*v.y, d*v.z );
00006 }


Member Data Documentation

double vec::x
 

$ V_0 $ component

Definition at line 7 of file vec.hpp.

Referenced by normalize(), operator *=(), operator()(), operator+=(), operator-(), operator-=(), operator/=(), operator=(), and vt2q().

double vec::y
 

$ V_1 $ component

Definition at line 8 of file vec.hpp.

Referenced by normalize(), operator *=(), operator()(), operator+=(), operator-(), operator-=(), operator/=(), operator=(), and vt2q().

double vec::z
 

$ V_2 $ component

Definition at line 9 of file vec.hpp.

Referenced by normalize(), operator *=(), operator()(), operator+=(), operator-(), operator-=(), operator/=(), operator=(), and vt2q().


The documentation for this class was generated from the following files:
Generated on Tue Mar 15 16:02:38 2005 for QVM by  doxygen 1.4.1