【问题标题】:Creating rotation matrix创建旋转矩阵
【发布时间】:2016-12-10 17:11:32
【问题描述】:

我需要创建一个用于旋转项目的旋转函数,它几乎可以在尝试执行 -sin 时起作用。 似乎没有允许这样做的功能。

Matrix.createRotation = function (rotation) {

    return new Matrix(Math.cos(rotation),  Math.sin(rotation), 0,
        Math.sin(rotation), Math.cos(rotation), 0, 0, 0, 1);
};

【问题讨论】:

  • (-1) * Math.sin(rotation) 这样的东西怎么样?那不应该工作吗?如在函数中应该是这样的,return new Matrix(Math.cos(rotation), (-1) * Math.sin(rotation), 0, Math.sin(rotation), Math.cos(rotation), 0, 0, 0, 1);
  • 是的,你是对的,它确实有效。
  • 在您的示例中,您甚至没有否定Math.sin(rotation) 的结果。它应该是-Math.sin(rotation) - 它比乘以-1 更快。如果你不否定sin(rotation)的结果,你怎么期待-sin(rotation)

标签: javascript matrix rotation linear-algebra


【解决方案1】:

您必须将Math.sin(rotation) 的结果否定为-Math.sin(rotation)

Matrix.createRotation = function (rotation)
{ 
    return new Matrix(
        Math.cos(rotation), -Math.sin(rotation), 0,
        Math.sin(rotation), Math.cos(rotation), 0,
        0, 0, 1
    );
};

请注意,-Math.sin(rotation)(-1)*Math.sin(rotation) 快。

【讨论】:

    猜你喜欢
    • 2016-12-13
    • 1970-01-01
    • 1970-01-01
    • 2019-02-08
    • 1970-01-01
    • 1970-01-01
    • 2011-05-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多