vec-calc.hpp

Go to the documentation of this file.
00001 //=============================================================================
00002 /*! normalize itself */
00003 inline void vec::normalize()
00004 {
00005   double myabs(abs(*this));
00006   x /=myabs;
00007   y /=myabs;
00008   z /=myabs;
00009 }
00010 
00011 ///////////////////////////////////////////////////////////////////////////////
00012 ///////////////////////////////////////////////////////////////////////////////
00013 ///////////////////////////////////////////////////////////////////////////////
00014 
00015 //=============================================================================
00016 /*! return abs */
00017 inline double abs(const vec& v)
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 }
00028 
00029 //=============================================================================
00030 /*! return norm */
00031 inline double norm(const vec& v)
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 }
00042 
00043 //=============================================================================
00044 /*! return the normalized vec */
00045 inline vec normal(const vec& v)
00046 {
00047   double abs_v(abs(v));
00048   return vec( v.x/abs_v, v.y/abs_v, v.z/abs_v );
00049 }
00050 
00051 //=============================================================================
00052 /*!  */
00053 inline vec rotate(const vec& v, const quat& q)
00054 {
00055   //return im( conj(q)*vr2q(v,0.)*q );
00056   return im( q*vr2q(v,0.)*conj(q) );
00057 }
00058 
00059 //=============================================================================
00060 /*!  */
00061 inline vec orbit(const vec& v, const quat& q)
00062 {
00063   return im( q*vr2q(v,0.)*conj(q) );
00064 }

Generated on Tue Mar 15 16:02:38 2005 for QVM by  doxygen 1.4.1