用欧拉角旋转一个四元数

Rotate a Quaternion with Euler angles using Eigen

本文关键字:一个 四元数 旋转      更新时间:2023-10-16

我正在尝试创建一个四元数,围绕欧拉角旋转它并将其转换回欧拉角。我用的是Eigen。从欧拉转换到四元数,反之亦然,但当我使用角轴旋转时,我的值大约下降了20 - 50%。例如,当我尝试从0,0,0旋转到90,50,60时,我得到x: 75,5 y: 103,13, z: 78,46。你知道我哪里拐错弯了吗?我使用102/YXZ惯例。我试图实现它像这里描述:旋转四元数欧拉角度输入。

  Vector3f retVector;
    Matrix3f rotFromMat, qautRotMatrix;
const auto fromPitch = xFrom*M_PI/360;
const auto fromYaw = zFrom*M_PI / 360;
const auto fromRoll = yFrom*M_PI / 360;

rotFromMat = AngleAxisf(fromRoll,  Vector3f::UnitY())
    * AngleAxisf(fromPitch, Vector3f::UnitX())
    * AngleAxisf(fromYaw,   Vector3f::UnitZ());
Quaternionf fromQuat(rotFromMat);
    fromQuat.normalize();
    fromQuat = fromQuat * AngleAxisf(yTo, Vector3f::UnitY());
    fromQuat = fromQuat * AngleAxisf(xTo, Vector3f::UnitX());
    fromQuat = fromQuat * AngleAxisf(zTo, Vector3f::UnitZ());

    qautRotMatrix = fromQuat.toRotationMatrix();
    retVector = quatRotMatrix.eulerAngles(1, 0, 2);
    retVector *= 360 / M_PI;
    return retVector; 

你没有详细说明如何复制这个。

但是我可以看出两个错误:*度和弧度的比值是180/PI,而不是360/PI。*你的轮换顺序不对!左侧正在旋转右侧:

fromQuat = AngleAxisf(...) * fromQuat;

从日期我猜你已经解决了这个问题,我在这里为新的观众评论