【问题标题】:Is the WPF Matrix3D.Rotate() function innacurate?WPF Matrix3D.Rotate() 函数是否不准确?
【发布时间】:2010-07-23 10:50:29
【问题描述】:

我目前正在尝试围绕 WPF 进行研究,并且正处于使用 Matrix3D 结构在坐标空间之间进行转换的阶段。

在意识到 WPF 在 Point3D 和 Vector3D 之间存在差异(那两个小时我永远不会回来......)之后,我可以设置一个平移矩阵。我现在正在尝试引入一个旋转矩阵,但它似乎给出了不准确的结果。这是我的世界坐标转换代码...

    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 度似乎返回浮点不准确。矩阵的 Offset 行似乎偏离了一个微小的因子(无论哪种方式都是 0.000001),这会在渲染上产生锯齿。我在这里遗漏了什么,还是我只需要手动将矩阵向上取整?

干杯

【问题讨论】:

    标签: c# wpf matrix rotation transformation


    【解决方案1】:

    即使使用双精度数学,矩阵乘法也会存在舍入误差。

    您正在执行 4 次乘法,然后将新矩阵中每个元素的结果相加。

    最好将Screen2World 矩阵设置为开始的平移矩阵,而不是将单位矩阵乘以平移然后乘以旋转。这是两次矩阵乘法,而不是一次和(多于)两倍的舍入误差。

    【讨论】:

      猜你喜欢
      • 2018-07-28
      • 1970-01-01
      • 2010-12-15
      • 2023-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-20
      • 2022-12-08
      相关资源
      最近更新 更多