Discuz! Board

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2|回复: 0
打印 上一主题 下一主题

[代码|Code]欧拉角≒矩阵|EulerAngles≒Matrix

[复制链接]

189

主题

189

帖子

580

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
580
跳转到指定楼层
楼主
发表于 2017-7-14 16:37:45 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式


by Akatsuki

  1. // 欧拉角转矩阵[] EulerAngles To Matrix
  2. void AngleMatrix(const float in[3], float out[4][4])
  3. {
  4.     float cx, sx, cy, sy, cz, sz;
  5.     float yx, yy;

  6.     cx = cos(in[0]);
  7.     sx = sin(in[0]);
  8.     cy = cos(in[1]);
  9.     sy = sin(in[1]);
  10.     cz = cos(in[2]);
  11.     sz = sin(in[2]);
  12.    
  13.     yx = sy*cx;
  14.     yy = sy*sx;

  15.     out[0][0] =  cy*cz;
  16.     out[0][1] = -cy*sz;
  17.     out[0][2] =     sy;
  18.     out[0][3] =  0;
  19.     out[1][0] =  yy*cz+cx*sz;
  20.     out[1][1] = -yy*sz+cx*cz;
  21.     out[1][2] = -sx;
  22.     out[1][3] =  0;
  23.     out[2][0] = -yx*cz+sx*sz;
  24.     out[2][1] =  yx*sz+sx*cz;
  25.     out[2][2] =  cx*cy;
  26.     out[2][3] =  0;
  27.     out[3][0] =  0;
  28.     out[3][1] =  0;
  29.     out[3][2] =  0;
  30.     out[3][3] =  1;
  31. }

  32. // 矩阵转欧拉角[] Matrix To EulerAngles
  33. void MatrixAngle(const float in[4][4], float out[3])
  34. {
  35.     float c;
  36.     float tx, ty;

  37.     out[1] = asin(in[0][2]);
  38.     c = cos(out[1]);
  39.     if (fabs(c)>0.005)
  40.     {
  41.         tx =  in[2][2]/c;
  42.         ty = -in[1][2]/c;
  43.         out[0] = atan2(ty, tx);
  44.         tx =  in[0][0]/c;
  45.         ty = -in[0][1]/c;
  46.         out[2] = atan2(ty, tx);
  47.     }
  48.     else
  49.     {
  50.         out[0] = 0;
  51.         tx = in[1][1];
  52.         ty = in[1][0];
  53.         out[2] = atan2(ty, tx);
  54.     }
  55. }
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Comsenz Inc.  

GMT+8, 2026-10-26 07:03 , Processed in 0.229355 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表