【问题标题】:Affine Rotation Matrices仿射旋转矩阵
【发布时间】:2016-12-28 06:05:21
【问题描述】:

我正在用 C++ 编写一个具有静态 RotationX() RotationY()RotationZ() 方法的 Matrix 类。如果在乘以向量之前将矩阵相乘,我得到的结果与将矩阵单独乘以向量的结果不同。

这段代码

Vec4 result1 { 1, 1, 1, 1 };
result1 = Matrix::RotationX(ToRadians(-90)) * result1;
result1 = Matrix::RotationY(ToRadians(90)) * result1;
result1 = Matrix::RotationZ(ToRadians(90)) * result1;
// result1 => { -1, -1, -1, 1 }

给出与此代码不同的结果

Vec4 result2 { 1, 1, 1, 1 };
auto rotation = Matrix::RotationX(ToRadians(-90)) *
                Matrix::RotationY(ToRadians(90)) *
                Matrix::RotationZ(ToRadians(90));
result2 = rotation * result2;
// result2 => { 1, 1, -1, 1 }

这里有什么问题?我可以提供我的旋转函数实现,但我想在发布代码之前确保这不是仿射变换的概念问题。

【问题讨论】:

    标签: c++ math matrix affinetransform


    【解决方案1】:

    您的第一个示例对应于矩阵乘法的逆序。比较:

    Z * (Y * (X * V))
    ((X * Y) * Z) * V
    

    但矩阵乘法不可交换!

    【讨论】:

    • 我没有意识到我的矩阵顺序不同 :) 谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-08
    • 2011-05-01
    相关资源
    最近更新 更多