欧拉角、四元数、旋转矩阵的互相转换

概述

方法来自于《3D数学基础,图形与游戏开发》这本书。
学习这些转换可以加深自己对这些知识点的理解~两两转换一共有六种情况,下面就依次列举一下这六种情况。

1.从欧拉角转换到矩阵

这种情况的转换不难,还记得我们的旋转矩阵长啥样吗,欧拉角的三个值就是坐标系绕着特定轴旋转的值,注意是坐标系旋转哦,点的旋转值是和坐标系的旋转值相反的,需要把旋转矩阵的角度取反。
比如下面就是绕y轴的旋转矩阵,角度h取反了,
[ c o s ( − h ) 0 − s i n ( − h ) 0 1 0 s i n ( − h ) 0 c o s ( − h ) ] \begin{bmatrix} cos(-h)&0&-sin(-h)\\ 0&1&0\\ sin(-h)&0&cos(-h)\\ \end{bmatrix} cos(h)0sin(h)010sin(h)0cos(h)
我们根据特定的顺序把三个旋转矩阵乘起来就行了,很简单的。
书上是先绕y轴旋转再绕x轴旋转,再绕z轴旋转,得到的结果为:
[ c o s h c o s b + s i n h s i n p s i n b − c o s h s i n b + s i n h s i n p c o s b s i n h c o s p s i n b c o s p c o s b c o s p − s i n p − s i n h c o s b + c o s h s i n p s i n b s i n b s i n h + c o s h s i n p c o s b c o s h c o s p ] \begin{bmatrix} coshcosb+sinhsinpsinb&-coshsinb+sinhsinpcosb&sinhcosp\\ sinbcosp&cosbcosp&-sinp\\ -sinhcosb+coshsinpsinb&sinbsinh+coshsinpcosb&coshcosp\\ \end{bmatrix} coshcosb+sinhsinpsinbsinbcospsinhcosb+coshsinpsinbcoshsinb+sinhsinpcosbcosbcospsinbsinh+coshsinpcosbsinhcospsinpcoshcosp
这个旋转矩阵是从惯性坐标系旋转到物体坐标系的旋转矩阵。h为绕y轴的旋转角度,p为绕x轴的旋转角度,b为绕z轴的旋转角度。

2.从旋转矩阵到欧拉角

当我们知道了从欧拉角到旋转矩阵的矩阵形式,倒推是一件非常简单的事情,假设上面的矩阵为M,则M23 = -sinp,我们能直接得到绕x轴的旋转角度p,然后把M21/M22能直接得到tanb,所以也能得到绕z的旋转角度b,把M13/M33也能直接得到tanh,然后就能得到角度h,于是这一切问题都解决了,是不是很容易。

3.从四元数转换到旋转矩阵

[ n x 2 ( 1 − c o s θ ) + c o s θ n x n y ( 1 − c o s θ ) + n z s i n θ n x n z ( 1 − c o s θ ) − n y s i n θ n x n y ( 1 − c o s θ ) − n z s i n θ n y 2 ( 1 − c o s θ ) + c o s θ n y n z ( 1 − c o s θ ) + n x s i n θ n x n z ( 1 − c o s θ ) + n y s i n θ n y n z ( 1 − 0 c o s θ ) − n x s i n θ n x 2 ( 1 − c o s θ ) + c o s θ ] \begin{bmatrix} n_x^2(1-cos\theta)+cos\theta & n_xn_y(1-cos\theta)+n_zsin\theta&n_xn_z(1-cos\theta)-n_ysin\theta\\ n_xn_y(1-cos\theta)-n_zsin\theta&n_y^2(1-cos\theta)+cos\theta&n_yn_z(1-cos\theta)+n_xsin_\theta\\ n_xn_z(1-cos\theta)+n_ysin\theta&n_yn_z(1-0cos\theta)-n_xsin\theta&n_x^2(1-cos\theta)+cos\theta \end{bmatrix} nx2(1cosθ)+cosθn

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值