GEL  2
GEL is a library for Geometry and Linear Algebra
/Users/jab/Documents/Teaching/02585/GEL2_and_demos/GEL/src/CGLA/Quatd.h
00001 #ifndef __CGLA_QUATD_H__
00002 #define __CGLA_QUATD_H__
00003 
00004 #include "ArithQuat.h"
00005 #include "Vec3d.h"
00006 #include "Vec4d.h"
00007 #include "Mat3x3d.h"
00008 #include "Mat4x4d.h"
00009 
00010 
00011 namespace CGLA {
00012 
00017         class Quatd : public ArithQuat<double,Vec3d,Quatd>
00018   {
00019   public:
00020                 Quatd() : ArithQuat<double, Vec3d, Quatd>() {}
00021 
00023     Quatd(const Vec3d& imaginary, double real = 1.0) : ArithQuat<double, Vec3d, Quatd>(imaginary, real) {}
00024 
00026     Quatd(double x, double y, double z, double _qw) :  ArithQuat<double, Vec3d, Quatd>(x,y,z,_qw) {}
00027 
00029                 explicit Quatd(const Vec4d& v) : ArithQuat<double, Vec3d, Quatd>(v[0], v[1], v[2], v[3]) {}
00030 
00031         
00033     Mat3x3d get_Mat3x3d() const
00034     {
00035       double s = 2/norm();
00036       // note that the all q_*q_ are used twice (optimize)
00037       return Mat3x3d(Vec3d(1.0 - s*(qv[1]*qv[1] + qv[2]*qv[2]),
00038                                  s*(qv[0]*qv[1] - qw*qv[2]),
00039                                  s*(qv[0]*qv[2] + qw*qv[1])),
00040                      Vec3d(      s*(qv[0]*qv[1] + qw*qv[2]),
00041                            1.0 - s*(qv[0]*qv[0] + qv[2]*qv[2]),
00042                                  s*(qv[1]*qv[2] - qw*qv[0])),
00043                      Vec3d(      s*(qv[0]*qv[2] - qw*qv[1]),
00044                                  s*(qv[1]*qv[2] + qw*qv[0]),
00045                            1.0 - s*(qv[0]*qv[0] + qv[1]*qv[1])));
00046     }
00047 
00049     Mat4x4d get_Mat4x4d() const
00050     {
00051       double s = 2/norm();
00052       // note that the all q_*q_ are used twice (optimize?)
00053       return Mat4x4d(Vec4d(1.0 - s*(qv[1]*qv[1] + qv[2]*qv[2]),
00054                                  s*(qv[0]*qv[1] - qw*qv[2]),
00055                                  s*(qv[0]*qv[2] + qw*qv[1]),
00056                            0.0),
00057                      Vec4d(      s*(qv[0]*qv[1] + qw*qv[2]),
00058                            1.0 - s*(qv[0]*qv[0] + qv[2]*qv[2]),
00059                                  s*(qv[1]*qv[2] - qw*qv[0]),
00060                            0.0),
00061                      Vec4d(      s*(qv[0]*qv[2] - qw*qv[1]),
00062                                  s*(qv[1]*qv[2] + qw*qv[0]),
00063                            1.0 - s*(qv[0]*qv[0] + qv[1]*qv[1]),
00064                            0.0),
00065                      Vec4d(0.0, 0.0, 0.0, 1.0));
00066     }
00067                 
00069   inline Quatd identity_Quatd()
00070   {
00071     return Quatd(Vec3d(0.0));
00072   }
00073 
00074         };
00075 
00076 }
00077 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations