Euler angle to Quaternion then Quaternion to euler angle(欧拉角到四元数然后四元数到欧拉角)
问题描述
我正在使用 lib glm (http://glm.g-truc.net/) 用于测试四元数,但我有问题;当我将欧拉角转换为四元数然后立即将四元数转换为欧拉角时,我的结果与我最初的欧拉角完全不同.这是正常的吗?会不会是轮换不是交际的?
I'm using lib glm (http://glm.g-truc.net/) for test quaternion but I've a problem; when I convert euler angle to quaternion then immediatly quaternion to euler angles, my result are totally different from my initial euler angles. Is this normal? Could it be because the rotations are not communative?
代码测试:
#include <glmquaternion.hpp>
#include <math.h>
#define PI M_PI
#define RADTODEG(x) ( (x) * 180.0 / PI )
#define DEGTORAD(x) ( (x) * PI / 180.0 )
int main( void )
{
float RotX = 90.f;
float RotY = 180.f;
float RotZ = -270.f;
if ( RotX || RotY || RotZ )
{
std::cout << "Init: x= " << RotX << ", y= " << RotY << ", z= " << RotZ << "
";
glm::quat key_quat(glm::detail::tvec3<float>(DEGTORAD( RotX ),
DEGTORAD( RotY ),
DEGTORAD( RotZ )));
glm::detail::tvec3<float> v = glm::eulerAngles(key_quat);
/* // the result is even worse with this code here
RotX = RADTODEG(v.x);
RotY = RADTODEG(v.y);
RotZ = RADTODEG(v.z);
*/
RotX = v.x;
RotY = v.y;
RotZ = v.z;
std::cout << "Final: x= " << RotX << ", y= " << RotY << ", z= " << RotZ << "
";
}
return (0);
}
结果:
Init: x= 90, y= 180, z= -270
Final: x= -90, y= -3.41509e-006, z= -90
提前谢谢你o/
推荐答案
是的,很正常.有两种方式可以用欧拉角表示相同的旋转.
Yes, it is normal. There are 2 ways to represent the same rotation with Euler angles.
我个人不喜欢欧拉角,它们会破坏您应用的稳定性.我会避免使用它们.另外,它们也不是很方便.
I personally don't like Euler angles, they mess up the stability of your app. I would avoid them. Plus, they are not very handy either.
这篇关于欧拉角到四元数然后四元数到欧拉角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:欧拉角到四元数然后四元数到欧拉角
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 从python回调到c++的选项 2022-11-16
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 静态初始化顺序失败 2022-01-01
- C++ 协变模板 2021-01-01
- 近似搜索的工作原理 2021-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- Stroustrup 的 Simple_window.h 2022-01-01