예제 #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);
        }
예제 #2
0
        public void TestTranspose()
        {
            var b = new RTF.Matrix(4, 4);

            b.SetRow(0, new double[] { 0, 9, 3, 0 });
            b.SetRow(1, new double[] { 9, 8, 0, 8 });
            b.SetRow(2, new double[] { 1, 8, 5, 3 });
            b.SetRow(3, new double[] { 0, 0, 5, 8 });

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

            e.SetColumn(0, new double[] { 0, 9, 3, 0 });
            e.SetColumn(1, new double[] { 9, 8, 0, 8 });
            e.SetColumn(2, new double[] { 1, 8, 5, 3 });
            e.SetColumn(3, new double[] { 0, 0, 5, 8 });

            Assert.Equal(e, b.Transpose());
        }