quaternion.cpp

Go to the documentation of this file.
00001 
00015 #include <cmath>
00016 #include <dlrNumeric/quaternion.h>
00017 
00018 namespace dlr {
00019 
00020   namespace numeric {
00021 
00022     // This member function normalizes the Quaternion, first computing
00023     // the magnitude of the Quaternion, and then dividing each element
00024     // by that value.
00025     void
00026     Quaternion::
00027     normalize()
00028     {
00029       // Skip all the effort if the Quaternion already has unit
00030       // magnitude.
00031       if(!m_isNormalized) {
00032         // First compute the magnitude of the Quaternion.
00033         double norm = std::sqrt(m_s*m_s + m_i*m_i + m_j*m_j + m_k*m_k);
00034 
00035         // Next some error checking.
00036         if(norm == 0) {
00037           // DLR_THROW(ValueException, "Quaternion::normalize()",
00038           //           "Can't normalize a zero magnitude Quaternion.");
00039           m_s = 1.0;
00040           m_i = 0.0;
00041           m_j = 0.0;
00042           m_k = 0.0;
00043           m_isNormalized = true;
00044         } else {
00045           // Finally, normalize.
00046           m_s /= norm;
00047           m_i /= norm;
00048           m_j /= norm;
00049           m_k /= norm;
00050           m_isNormalized = true;
00051         }
00052       }
00053     }
00054 
00055   } // namespace numeric
00056   
00057 } // namespace dlr

Generated on Mon Jul 9 20:34:03 2007 for dlrLibs Utility Libraries by  doxygen 1.5.2