Exemplo n.º 1
0
        public void PuttingItTogether()
        {
            var a = new RTF.Matrix(4, 4);

            a.SetRow(0, new double[] { 3, -9, 7, 3 });
            a.SetRow(1, new double[] { 3, -8, 2, -9 });
            a.SetRow(2, new double[] { -4, 4, 4, 1 });
            a.SetRow(3, new double[] { -6, 5, -1, 1 });

            var identity = RTF.Matrix.GetIdentity(4, 4);

            Assert.Equal(identity, identity.Inverse());

            var idInverted = a * a.Inverse();

            CustomAssert.Equal(identity, idInverted, 0);

            var transposeInvert = a.Transpose().Inverse();
            var invertTranspose = a.Inverse().Transpose();


            CustomAssert.Equal(transposeInvert, invertTranspose, 5);

            var modifiedIdentity = RTF.Matrix.GetIdentity(4, 4);

            modifiedIdentity[2, 2] = 6;
            var tuple         = new double[] { 1, 2, 3, 4 };
            var tupleIdentity = identity * tuple;
            var newTuple      = modifiedIdentity * tuple;

            Assert.Equal(tuple, tupleIdentity);
            Assert.NotEqual(tuple, newTuple);
        }
Exemplo n.º 2
0
        public void Inverse()
        {
            var e = new RTF.Matrix(4, 4);

            e.SetRow(0, new double[] { -5, 2, 6, -8 });
            e.SetRow(1, new double[] { 1, -5, 1, 8 });
            e.SetRow(2, new double[] { 7, 7, -6, -7 });
            e.SetRow(3, new double[] { 1, -3, 7, 4 });

            double r1 = -160d / 532;
            double r2 = 105d / 532;
            var    b  = e.Inverse();

            Assert.Equal(532, e.Determinant());
            Assert.Equal(-160, RTF.Matrix.Cofactor(e, 2, 3));
            Assert.Equal(r1, b[3, 2]);
            Assert.Equal(105, RTF.Matrix.Cofactor(e, 3, 2));
            Assert.Equal(r2, b[2, 3]);
        }
Exemplo n.º 3
0
        public void Inverse3()
        {
            var a = new RTF.Matrix(4, 4);

            a.SetRow(0, new double[] { 9, 3, 0, 9 });
            a.SetRow(1, new double[] { -5, -2, -6, -3 });
            a.SetRow(2, new double[] { -4, 9, 6, 4 });
            a.SetRow(3, new double[] { -7, 6, 6, 2 });

            var e = new RTF.Matrix(4, 4);

            e.SetRow(0, new double[] { -0.04074, -0.07778, 0.14444, -0.22222 });
            e.SetRow(1, new double[] { -0.07778, 0.03333, 0.36667, -0.33333 });
            e.SetRow(2, new double[] { -0.02901, -0.14630, -0.10926, 0.12963 });
            e.SetRow(3, new double[] { 0.17778, 0.06667, -0.26667, 0.33333 });

            var inverse = a.Inverse();

            CustomAssert.Equal(e, inverse, 5);
        }
Exemplo n.º 4
0
        public void Inverse2()
        {
            var a = new RTF.Matrix(4, 4);

            a.SetRow(0, new double[] { 8, -5, 9, 2 });
            a.SetRow(1, new double[] { 7, 5, 6, 1 });
            a.SetRow(2, new double[] { -6, 0, 9, 6 });
            a.SetRow(3, new double[] { -3, 0, -9, -4 });

            var e = new RTF.Matrix(4, 4);

            e.SetRow(0, new double[] { -0.15385, -0.15385, -0.28205, -0.53846 });
            e.SetRow(1, new double[] { -0.07692, 0.12308, 0.02564, 0.03077 });
            e.SetRow(2, new double[] { 0.35897, 0.35897, 0.43590, 0.92308 });
            e.SetRow(3, new double[] { -0.69231, -0.69231, -0.76923, -1.92308 });

            var inverse = a.Inverse();

            CustomAssert.Equal(e, inverse, 5);
        }
Exemplo n.º 5
0
        public void MultiplyingProductByInverse()
        {
            var a = new RTF.Matrix(4, 4);

            a.SetRow(0, new double[] { 3, -9, 7, 3 });
            a.SetRow(1, new double[] { 3, -8, 2, -9 });
            a.SetRow(2, new double[] { -4, 4, 4, 1 });
            a.SetRow(3, new double[] { -6, 5, -1, 1 });

            var b = new RTF.Matrix(4, 4);

            b.SetRow(0, new double[] { 8, 2, 2, 2 });
            b.SetRow(1, new double[] { 3, -1, 7, 0 });
            b.SetRow(2, new double[] { 7, 0, 5, 4 });
            b.SetRow(3, new double[] { 6, -2, 0, 5 });

            var c = a * b;
            var e = c * b.Inverse();


            CustomAssert.Equal(e, a, 0);
        }