通给给定旋转轴向量v,旋转角度ang,计算出旋转矩阵

来源:互联网 发布:搜本子的软件 编辑:程序博客网 时间:2024/04/30 11:03

chai3d中通过计算旋转轴和角度来获得旋转矩阵Matrix3

[cpp] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. inline bool rotateAboutLocalAxisRad(const cVector3d& a_axis,   
  2.                                      const double& a_angleRad)  
  3.  {  
  4.      // compute length of axis vector  
  5.      double length = a_axis.length();  
  6.   
  7.   
  8.      // check length of axis vector  
  9.      if (length < C_TINY)  
  10.      {  
  11.          // rotation matrix could not be computed because axis vector is not defined  
  12.          return (false);  
  13.      }  
  14.   
  15.   
  16.      // normalize axis vector  
  17.      double f = 1.0 / length;  
  18.      double x = f * a_axis(0);  
  19.      double y = f * a_axis(1);  
  20.      double z = f * a_axis(2);  
  21.   
  22.   
  23.      // compute rotation matrix  
  24.      double c = ::cos(a_angleRad);  
  25.      double s = ::sin(a_angleRad);  
  26.      double v = 1-c;  
  27.   
  28.   
  29.      cMatrix3d m;  
  30.      m(0,0) = x*x*v+c;     m(0,1) = x*y*v-z*s;  m(0,2) = x*z*v+y*s;  
  31.      m(1,0) = x*y*v+z*s;   m(1,1) = y*y*v+c;    m(1,2) = y*z*v-x*s;  
  32.      m(2,0) = x*z*v-y*s;   m(2,1) = y*z*v+x*s;  m(2,2) = z*z*v+c;  
  33.   
  34.   
  35.      (*this) = (*this)*m;  
  36.   
  37.   
  38.      // return success  
  39.      return (true);  
  40.  }  

上面的函数中的绕任意轴旋转获得的旋转矩阵的算法实现思路如下:

根据Goldman给出的公式进行计算,这个公式有点复杂:


具体推导过程可以参考:

http://www.cppblog.com/lovedday/archive/2008/01/12/41031.html

http://www.cnblogs.com/cg_ghost/archive/2012/04/27/2473347.html

0 0
原创粉丝点击