Biomechanical Joint Model
 Author: Anderson Maciel

implicit/LinAlg/quat.h

Go to the documentation of this file.
00001 #ifndef AMAURY_QUAT_H
00002 #define AMAURY_QUAT_H
00003 
00004 
00005 #define  QUAT_X  0
00006 #define  QUAT_Y  1
00007 #define  QUAT_Z  2
00008 #define  QUAT_W  3
00009 
00010 #include "vec.h"
00011 #include "hmat.h"
00012 
00013 namespace LinAlg{
00014 
00015  
00016 class QUAT : public VEC
00017 {
00018 public:
00019    QUAT(const QUAT &Q) : VEC(Q) {};
00020    explicit QUAT(const REAL& value = 0) : VEC(4, value) {};
00021    explicit QUAT(const VEC &V) : VEC(V) {};
00022    explicit QUAT(const char *s) : VEC(4,s) {};
00023    explicit QUAT(const float *v) : VEC(v,4) {};
00024    QUAT(const HMAT &M);
00025    QUAT(REAL theta, const VEC &N) : VEC(4) 
00026    { 
00027       assert(N.dim()==3);
00028       VEC T(N); T.normalize();
00029       REAL s = sin(theta/2);
00030       v_[QUAT_W]=cos(theta/2); 
00031       v_[QUAT_X]=s*T[0]; 
00032       v_[QUAT_Y]=s*T[1]; 
00033       v_[QUAT_Z]=s*T[2];
00034    }; 
00035  
00036    void set(const Vector &Q) 
00037    {
00038            v_[QUAT_W]= Q[3];
00039            v_[QUAT_X]= Q[0];
00040            v_[QUAT_Y]= Q[1];
00041        v_[QUAT_Z]= Q[2];
00042    };
00043 
00044    void inverse();
00045    void conjugate();
00046    operator HMAT() const;
00047    friend QUAT operator*(const QUAT &A, const QUAT &B);
00048 
00049    static void slerp (const QUAT &left, const QUAT &right, REAL u, QUAT &result);
00050    static REAL dist(const QUAT &left, const QUAT &right) { return acosf(dot_prod(left,right)); }
00051 };
00052  
00053  inline void QUAT::inverse(){
00054    REAL qn = norm();
00055    
00056    v_[QUAT_W] =  v_[QUAT_W] / qn;
00057    v_[QUAT_X] = -v_[QUAT_X] / qn;
00058    v_[QUAT_Y] = -v_[QUAT_Y] / qn;
00059    v_[QUAT_Z] = -v_[QUAT_Z] / qn;
00060  }
00061  
00062  inline void QUAT::conjugate(){
00063      v_[QUAT_X] = -v_[QUAT_X];
00064      v_[QUAT_Y] = -v_[QUAT_Y];
00065      v_[QUAT_Z] = -v_[QUAT_Z];
00066  }
00067  
00068 
00069 }
00070 #endif

Generated on Thu Dec 1 10:13:39 2005 for COME - Biomechanical Joint Model by  doxygen 1.4.5