CPPLapack
 All Classes Files Functions Variables Friends
dgematrix_small-specialized.hpp
Go to the documentation of this file.
00001 //=============================================================================
00002 /*! calculate determinant */
00003 inline double det(const dgemat2& A)
00004 {VERBOSE_REPORT;
00005   return A(0,0)*A(1,1)-A(0,1)*A(1,0);
00006 }
00007 
00008 //=============================================================================
00009 /*! calculate inverse */
00010 inline dgemat2 inv(const dgemat2& A)
00011 {VERBOSE_REPORT;
00012   const double Adet( det(A) );
00013   dgemat2 Ainv;
00014   Ainv(0,0)= A(1,1)/Adet;  Ainv(0,1)=-A(0,1)/Adet;
00015   Ainv(1,0)=-A(1,0)/Adet;  Ainv(1,1)= A(0,0)/Adet;
00016   return Ainv;
00017 }
00018 
00019 //=============================================================================
00020 /*! return rotated tensor */
00021 inline dgemat2 rotate(const dgemat2& m, const double& theta)
00022 {VERBOSE_REPORT;
00023   //dgemat2 R(t2m(theta)); return R*m*t(R);//too slow
00024   double c(cos(theta)), s(sin(theta));
00025   double cc(c*c), cs(c*s), ss(s*s);
00026   dgemat2 mat;
00027   mat(0,0) =m(0,0)*cc -(m(0,1)+m(1,0))*cs +m(1,1)*ss;
00028   mat(0,1) =m(0,1)*cc +(m(0,0)-m(1,1))*cs -m(1,0)*ss;
00029   mat(1,0) =m(1,0)*cc +(m(0,0)-m(1,1))*cs -m(0,1)*ss;
00030   mat(1,1) =m(1,1)*cc +(m(0,1)+m(1,0))*cs +m(0,0)*ss;
00031   return mat;
00032 }
00033 
00034 //=============================================================================
00035 /*! convert theta to 2x2 rotational matrix */
00036 inline dgemat2 t2m(const double& theta)
00037 {VERBOSE_REPORT;
00038   dgemat2 R;
00039   R(0,0)=cos(theta); R(0,1)=-sin(theta);
00040   R(1,0)=sin(theta); R(1,1)=cos(theta);
00041   return R;
00042 }
00043 
00044 ///////////////////////////////////////////////////////////////////////////////
00045 ///////////////////////////////////////////////////////////////////////////////
00046 ///////////////////////////////////////////////////////////////////////////////
00047 ///////////////////////////////////////////////////////////////////////////////
00048 ///////////////////////////////////////////////////////////////////////////////
00049 ///////////////////////////////////////////////////////////////////////////////
00050 ///////////////////////////////////////////////////////////////////////////////
00051 ///////////////////////////////////////////////////////////////////////////////
00052 ///////////////////////////////////////////////////////////////////////////////
00053 
00054 //=============================================================================
00055 /*! calculate determinant */
00056 inline double det(const dgemat3& A)
00057 {VERBOSE_REPORT;
00058   return
00059     +A(0,0)*A(1,1)*A(2,2) -A(0,0)*A(1,2)*A(2,1)
00060     +A(0,1)*A(1,2)*A(2,0) -A(0,1)*A(1,0)*A(2,2)
00061     +A(0,2)*A(1,0)*A(2,1) -A(0,2)*A(1,1)*A(2,0);
00062 }
00063 
00064 //=============================================================================
00065 /*! calculate inverse */
00066 inline dgemat3 inv(const dgemat3& A)
00067 {VERBOSE_REPORT;
00068   const double Adet( det(A) );
00069   dgemat3 Ainv;
00070   Ainv(0,0) =(A(1,1)*A(2,2)-A(1,2)*A(2,1))/Adet;
00071   Ainv(0,1) =(A(0,2)*A(2,1)-A(0,1)*A(2,2))/Adet;
00072   Ainv(0,2) =(A(0,1)*A(1,2)-A(0,2)*A(1,1))/Adet;
00073   Ainv(1,0) =(A(1,2)*A(2,0)-A(1,0)*A(2,2))/Adet;
00074   Ainv(1,1) =(A(0,0)*A(2,2)-A(0,2)*A(2,0))/Adet;
00075   Ainv(1,2) =(A(0,2)*A(1,0)-A(0,0)*A(1,2))/Adet;
00076   Ainv(2,0) =(A(1,0)*A(2,1)-A(1,1)*A(2,0))/Adet;
00077   Ainv(2,1) =(A(0,1)*A(2,0)-A(0,0)*A(2,1))/Adet;
00078   Ainv(2,2) =(A(0,0)*A(1,1)-A(0,1)*A(1,0))/Adet;
00079   return Ainv;
00080 }
00081 
00082 //=============================================================================
00083 /*!  */
00084 inline dgemat3 rotate(const dgemat3& m, const dquater& q)
00085 {VERBOSE_REPORT;
00086   dgemat3 R(q2m(q));
00087   return R*m*t(R);
00088 }
00089 
00090 //=============================================================================
00091 /*!  */
00092 inline dquater m2q(const dgemat3& m)
00093 {VERBOSE_REPORT;
00094   dcovec3 v( m(2,1)-m(1,2), m(0,2)-m(2,0), m(1,0)-m(0,1) );
00095   double t( acos(0.5*(m(0,0)+m(1,1)+m(2,2)-1.)) );
00096   return vt2q(v,t);
00097 }
 All Classes Files Functions Variables Friends