【问题标题】:Implement 2x2 rotation matrix in c#在 C# 中实现 2x2 旋转矩阵
【发布时间】:2013-02-20 09:15:24
【问题描述】:

我使用以下代码旋转矢量:

   var newVectorX = Math.Cos(step) * normalizedVector.X 
                                 - Math.Sin(step) * normalizedVector.Y;

                var newVectorY = - Math.Sin(step) * (normalizedVector.X )
                                 + Math.Cos(step) * normalizedVector.Y;

我尝试创建一个 2x2 矩阵,这样我就可以将我的归一化向量与矩阵相乘。结果将是新的旋转矢量而不是坐标。

很遗憾System.Windows.Media.Matrix 不支持 2x2 矩阵。到目前为止,我找不到这个旋转矩阵的任何实现。你将如何实现它?

【问题讨论】:

    标签: c# vector matrix rotational-matrices


    【解决方案1】:

    实际上,System.Windows.Media.Matrix 正是您所需要的。虽然您似乎想要一个 2x2 矩阵,但使用 3x3 矩阵也可以进行转换。只需使用System.Windows.Media.Matrix 并忽略不需要的部分。

    Matrix rotate = Matrix.Identity;
    rotate.Rotate(step * 180 / Math.PI);    // Rotate() takes degrees
    Vector newVector = rotate.Transform(normalizedVector);
    

    【讨论】:

    • Matrix.Identity.Rotate 不返回矩阵
    • 解决方案见我上面的评论
    • 是的,我将 Rotate 步骤移到了单独的语句中。我修复了度数的转换。
    • 啊,我刚刚注意到了。我希望一个工作人员理解我必须接受这个答案,因为这是我正在寻找的实现。
    猜你喜欢
    • 2013-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-09
    • 2014-09-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多