math - 将欧拉角转换为四元数时更改 XYZ 顺序

标签 math geometry quaternions euler-angles

我使用以下代码从以弧度为单位的 XYZ 欧拉角生成四元数:

c1 = Math.cos( x / 2 )
c2 = Math.cos( y / 2 )
c3 = Math.cos( z / 2 )

s1 = Math.sin( x / 2 )
s2 = Math.sin( y / 2 )
s3 = Math.sin( z / 2 )

quaternion = [
              c1 * c2 * c3 - s1 * s2 * s3,
              s1 * c2 * c3 + c1 * s2 * s3,
              c1 * s2 * c3 - s1 * c2 * s3,
              c1 * c2 * s3 + s1 * s2 * c3,
             ]

来自: http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToQuaternion/index.htm

这会产生一个四元数,它首先围绕 z 轴旋转,然后是 y,最后是 x 轴 - Z-Y-X。是否可以更改此公式,使其以不同的顺序绕轴旋转?我正在寻找的是相反的,所以 X-Y-Z。

最佳答案

如果有人感兴趣...

是的,你可以,结果这次我只需要交换加号和减号就可以得到 X-Y-Z 订单(传统上写成 ZYX)。 像这样...

       [
        c1 * c2 * c3 + s1 * s2 * s3,
        s1 * c2 * c3 - c1 * s2 * s3,
        c1 * s2 * c3 + s1 * c2 * s3,
        c1 * c2 * s3 - s1 * s2 * c3
        ]

Three.js 在函数 THREE.Quaternion.setFromEuler 中包含各种 xyz 顺序的不同公式的完整列表

https://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToQuaternion/steps/index.htm

关于math - 将欧拉角转换为四元数时更改 XYZ 顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50011864/

相关文章:

c++ - 我的 RC6 实现有什么问题?

检查一个数字是否是 C 中两个平方的和

c - 无法将二维 float 组分配给指针到指针到浮点

c++ - 如何用glm旋转3D相机

c++ - 四元数和翻译

确定线性丢番图方程非负值解存在性的算法

plot - 用圆点填充圆,使用偏向圆的边缘

java - 圆碰撞错误,圆绕不动的圆运行

quaternions - 使用向上向量查看四元数

php - 用数学替换 elseif