示例#1
0
        public void Basic()
        {
            var rng = new Random(1);
            var M   = m4x4.Random4x4(-5, +5, rng);

            // Compare with m4x4
            var m = new Matrix(4, 4);

            for (int v = 0; v != 4; ++v)
            {
                for (int c = 0; c != 4; ++c)
                {
                    m[v, c] = M[v][c];
                }
            }

            Assert.True(Matrix.FEql(m, M));

            Assert.True(Math_.FEql(M.w.x, m[3, 0]));
            Assert.True(Math_.FEql(M.x.w, m[0, 3]));
            Assert.True(Math_.FEql(M.z.z, m[2, 2]));

            Assert.True(Math_.IsInvertible(M));
            Assert.True(Matrix.IsInvertible(m));

            var M1 = Math_.Invert(M);
            var m1 = Matrix.Invert(m);

            Assert.True(Matrix.FEql(m1, M1));

            var M2 = Math_.Transpose(M);
            var m2 = Matrix.Transpose(m);

            Assert.True(Matrix.FEql(m2, M2));
        }
示例#2
0
        public void TestInversion()
        {
            var rng = new Random();
            {
                var m      = m3x4.Random(v4.Random3N(0, rng), -Math_.TauF, +Math_.TauF, rng);
                var inv_m0 = Math_.InvertFast(m);
                var inv_m1 = Math_.Invert(m);
                Assert.True(Math_.FEqlRelative(inv_m0, inv_m1, 0.001f));
            } {
                for (; ;)
                {
                    var m = m3x4.Random(-5.0f, +5.0f, 0, rng);
                    if (!Math_.IsInvertible(m))
                    {
                        continue;
                    }
                    var inv_m = Math_.Invert(m);
                    var I0    = inv_m * m;
                    var I1    = m * inv_m;

                    Assert.True(Math_.FEqlRelative(I0, m3x4.Identity, 0.001f));
                    Assert.True(Math_.FEqlRelative(I1, m3x4.Identity, 0.001f));
                    break;
                }
            } {
                var m = new m3x4(
                    new v4(0.25f, 0.5f, 1.0f, 0.0f),
                    new v4(0.49f, 0.7f, 1.0f, 0.0f),
                    new v4(1.0f, 1.0f, 1.0f, 0.0f));
                var INV_M = new m3x4(
                    new v4(10.0f, -16.666667f, 6.66667f, 0.0f),
                    new v4(-17.0f, 25.0f, -8.0f, 0.0f),
                    new v4(7.0f, -8.333333f, 2.333333f, 0.0f));

                var inv_m = Math_.Invert(m);
                Assert.True(Math_.FEqlRelative(inv_m, INV_M, 0.001f));
            }
        }