2

我正在尝试从欧拉三元组和旋转顺序创建一个 4x4 仿射变换矩阵。我希望得到的矩阵在外部表示旋转(即固定框架)。我的应用程序使用左手坐标系和列向量。

按照WikipediaVectorAlgebra提供的数学计算,方程应为:

在此处输入图像描述

但是,如果我在 zAxis 上旋转任意量,则会在对象的局部等效轴上执行以下 yAxis 或 zAxis 旋转。这与我想要的相反!

我正在使用的代码如下:

Matrix4f Sy_3dMath::createRotationMatrix( Axis axis, float radians )
{
    float c = cos( radians );
    float s = sin( radians );

    if ( axis == X ) {
        return ( Matrix4f() << 1.0f, 0.0f,  0.0f, 0.0f,
                               0.0f, c,    -s,    0.0f,
                               0.0f, s,     c,    0.0f,
                               0.0f, 0.0f,  0.0f, 1.0f ).finished();
    } else if ( axis == Y ) {
        return ( Matrix4f() <<  c,    0.0f, s,    0.0f,
                                0.0f, 1.0f, 0.0f, 0.0f,
                               -s,    0.0f, c,    0.0f,
                                0.0f, 0.0f, 0.0f, 1.0f ).finished();
    } else {
        return ( Matrix4f() << c,   -s,    0.0f, 0.0f,
                               s,    c,    0.0f, 0.0f,
                               0.0f, 0.0f, 1.0f, 0.0f,
                               0.0f, 0.0f, 0.0f, 1.0f ).finished();
    }
}

Matrix4f Sy_3dMath::matrixFromEulerAngles( const Vector3f& euler,
                                           Sy_3dMath::RotationOrder order )
{
    EulerData ed = getEulerData( order );
    return createRotationMatrix( static_cast< Axis >( ed.k ), euler( ed.k ) ) *
           createRotationMatrix( static_cast< Axis >( ed.j ), euler( ed.j ) ) *
           createRotationMatrix( static_cast< Axis >( ed.i ), euler( ed.i ) );
}

EulerData是一个简单的结构,包含 3 个表示Axis索引的整数(即 2 == zAxis == k,0 == xAxis == i)。

任何人都可以看到我的代码或理解中的缺陷吗?线性代数对我来说并不是自然而然的......

4

1 回答 1

0

I won't mark this as answer, as I don't understand why I'm seeing this behaviour when the whole point of extrinsic Euler rotations (as far as I can tell) is fixed world axis rotation, but Blender has exactly the same behaviour as my own app.

I'd like to think that someone in the last 20 years would have spotted a massive rotation flaw in Blender, so the behaviour I'm seeing must be expected...

If someone can explain why, I'll happily mark their answer as accepted!

于 2013-07-15T20:51:15.280 回答