views:

18

answers:

1

I'm currently trying to wrap my head around WPF, and I'm at the stage of converting between coordinate spaces with Matrix3D structures.

After realising WPF has differences between Point3D and Vector3D (thats two hours I'll never get back...) I can get a translation matrix set up. I'm now trying to introduce a rotation matrix, but it seems to be giving innacurate results. Here is my code for my world coordinate transformation...

    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);


    }

The translation appears to be working fine, the rotation by 90 degrees however seems to return floating point inaacuracies. The Offset row of the matrix seems to be off by a slight factor (0.000001 either way) which is producing aliasing on the renders. Is there something I'm missing here, or do I just need to manually round the matrix up?

Cheers

+1  A: 

Even with double precision mathematics there will be rounding errors with matrix multiplication.

You are performing 4 multiplications and then summing the results for each element in the new matrix.

It might be better to set your Screen2World matrix up as the translation matrix to start with rather than multiplying an identity matrix by your translation and then by the rotation. That's two matrix multiplications rather than one and (more than) twice the rounding error.

ChrisF