quaternion.h

Go to the documentation of this file.
00001 
00014 #ifndef _DLR_QUATERNION_H_
00015 #define _DLR_QUATERNION_H_
00016 
00017 namespace dlr {
00018 
00019   namespace numeric {
00020     
00033     class Quaternion {
00034     public:
00035 
00040       Quaternion() 
00041         : m_s(1.0), m_i(0.0), m_j(0.0), m_k(0.0), m_isNormalized(true) {}
00042 
00063       Quaternion(double s, double i, double j, double k,
00064                  bool isNormalized=false) 
00065         : m_s(s), m_i(i), m_j(j), m_k(k), m_isNormalized(isNormalized) {}
00066 
00073       Quaternion(const Quaternion &source) :
00074         m_s(source.m_s), m_i(source.m_i), m_j(source.m_j), m_k(source.m_k),
00075         m_isNormalized(source.m_isNormalized) {}
00076 
00080       virtual
00081       inline
00082       ~Quaternion() {}
00083 
00091       inline
00092       double
00093       s() const { return m_s; };
00094 
00102       inline
00103       double
00104       i() const { return m_i; };
00105 
00113       inline
00114       double
00115       j() const { return m_j; };
00116 
00124       inline
00125       double
00126       k() const { return m_k; };
00127 
00135       bool
00136       isNormalized() {return m_isNormalized;}
00137 
00145       void
00146       normalize();
00147 
00169       inline
00170       void
00171       setValue(double s, double i, double j, double k,
00172                bool isNormalized = false) {
00173         m_s = s; m_i = i; m_j = j; m_k = k; m_isNormalized = isNormalized;
00174       }
00175 
00183       inline
00184       Quaternion&
00185       operator=(const Quaternion &source) {
00186         setValue(source.m_s, source.m_i, source.m_j, source.m_k);
00187         m_isNormalized = source.m_isNormalized;
00188         return *this;
00189       }
00190     
00191     private:
00192       // Components of the quaternion are listed in order.
00193       double m_s;
00194       double m_i;
00195       double m_j;
00196       double m_k;
00197 
00198       // A flag to avoid repeatedly re-normalizing.
00199       bool m_isNormalized;
00200     };
00201 
00202     /* ======================= Non-member functions ===================== */
00203 
00218     inline
00219     Quaternion
00220     conjugate(const Quaternion& source) {
00221       return Quaternion(source.s(), -(source.i()), -(source.j()), -(source.k()));
00222     }
00223   
00224   } // namespace numeric
00225 
00226 } // namespace dlr
00227 
00228 
00229 /* ======= Declarations to maintain compatibility with legacy code. ======= */
00230 
00231 namespace dlr {
00232 
00233   using numeric::Quaternion;
00234 
00235 } // namespace dlr
00236 
00237 #endif // #ifndef _DLR_QUATERNION_H_

Generated on Wed Nov 25 00:42:42 2009 for dlrUtilities Utility Library by  doxygen 1.5.8