C# WPF Matrix3D.Rotate()函数是否正确?
我现在正试图用WPF来表达我的想法,我正处于用Matrix3D结构在坐标空间之间转换的阶段 在意识到WPF在Point3D和Vector3D之间存在差异后(这两个小时我再也回不来了…),我可以设置一个翻译矩阵。我现在尝试引入一个旋转矩阵,但它似乎给出了不准确的结果。这是我的世界坐标转换代码C# WPF Matrix3D.Rotate()函数是否正确?,c#,wpf,matrix,rotation,transformation,C#,Wpf,Matrix,Rotation,Transformation,我现在正试图用WPF来表达我的想法,我正处于用Matrix3D结构在坐标空间之间转换的阶段 在意识到WPF在Point3D和Vector3D之间存在差异后(这两个小时我再也回不来了…),我可以设置一个翻译矩阵。我现在尝试引入一个旋转矩阵,但它似乎给出了不准确的结果。这是我的世界坐标转换代码 private Point3D toWorldCoords(int x, int y) { Point3D inM = new Point3D(x, y, 0);
private Point3D toWorldCoords(int x, int y)
{
Point3D inM = new Point3D(x, y, 0);
//setup matrix for screen to world
Screen2World = Matrix3D.Identity;
Screen2World.Translate(new Vector3D(-200, -200, 0));
Screen2World.Rotate(new Quaternion(new Vector3D(0, 0, 1), 90));
//do the multiplication
Point3D outM = Point3D.Multiply(inM, Screen2World);
//return the transformed point
return new Point3D(outM.X, outM.Y, m_ZVal);
}
翻译似乎工作良好,旋转90度似乎返回浮点不准确。矩阵的偏移行似乎被一个微小的因子(0.000001)关闭,这会在渲染上产生锯齿。这里有我遗漏的东西吗,还是我只需要手动对矩阵进行取整
欢呼即使使用双精度数学,矩阵乘法也会有舍入误差 您将执行4次乘法,然后对新矩阵中每个元素的结果求和 最好先将
Screen2World
矩阵设置为平移矩阵,而不是将单位矩阵乘以平移,然后再乘以旋转。这是两个矩阵乘法,而不是一个和(超过)两倍的舍入误差