我正在尝试使用四元数绕Y轴将一个物体旋转45度。在指定四元数后,我尝试获取旋转矩阵。但是我看到的值是不正确的。
Eigen::Quaterniond q;
q.x() = 0;
q.y() = 1;
q.z() = 0;
q.w() = PI/8; // Half of the rotation angle must be specified, even IDK why
Eigen::Matrix3d R = q.normalized().toRotationMatrix();
std::cout << "R=" << std::endl << R << std::endl;
输出:
R=
-0.732 -0 -0.680
0 1 -0
0.680 0 -0.732
由于OpenGL沿Y轴的旋转矩阵应为:
因此,我期望的输出应该是:
R=
0.707 0 0.707
0 1 0
-0.707 0 0.707
不仅值偏差很小,而且错误的符号导致了一些意外的旋转。由于有负号,我的魔方会多转180度加上指定的角度。我已经为此苦恼了一整天,有人能告诉我我错在哪里吗?
PI/4
,我必须将其指定为PI/8
。 - DollarAkshayw = cos(theta/2), x = axis_x * sin(theta / 2), y = axis_y * sin(theta / 2), z = axis_z * sin(theta / 2)
。或者在eigen中,使用这个构造函数Quaternion (const AngleAxisType &aa)
。 - Rostislav