当前位置: 首页>>代码示例>>C#>>正文


C# Matrix.Invert方法代码示例

本文整理汇总了C#中System.Matrix.Invert方法的典型用法代码示例。如果您正苦于以下问题:C# Matrix.Invert方法的具体用法?C# Matrix.Invert怎么用?C# Matrix.Invert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Matrix的用法示例。


在下文中一共展示了Matrix.Invert方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConvertBasis

        /// <summary>
        /// Converts the bases for the specified vector from the basis definition vectors.
        /// </summary>
        /// <param name="b1">The first basis definition vector.</param>
        /// <param name="b2">The second basis definition vector.</param>
        /// <param name="w">The vector to convert bases on.</param>
        /// <returns>The new basis of the vector.</returns>
        public static Vector2 ConvertBasis( Vector2 b1, Vector2 b2, Vector2 w )
        {
            //
            // [w] = B^(-1) * w = [ B.M11 * w.X + B.M12 * w.Y ]
            //					  [ B.M21 * w.X + B.M22 * w.Y ]
            //
            Vector2 basis = Vector2.Empty;
            Matrix B = new Matrix();

            // Build inverse basis matrix
            B.M11 = b1.X;
            B.M21 = b1.Y;
            B.M12 = b2.X;
            B.M22 = b2.Y;
            B.M33 = 1;
            B.M44 = 1;

            B.Invert();

            // Determine basis
            basis.X = B.M11 * w.X + B.M12 * w.Y;
            basis.Y = B.M21 * w.X + B.M22 * w.Y;

            return basis;
        }
开发者ID:stormont,项目名称:terraingine,代码行数:32,代码来源:VectorMath.cs

示例2: TestInverse4

		public void TestInverse4()
		{
			// test identity inverse
			var m = Matrix.GetIdentity(4);

			Assert.IsTrue(Matrix.AreEqual(m.Invert(), new Matrix(new float[,] {{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}})));

			// test a known inverse
			m = new Matrix(new[,]
			               	{
			               		{0.100f, 0.200f, 0.300f, 1.300f},
			               		{-0.400f, 0.500f, 0.600f, 1.400f},
			               		{0.700f, 0.800f, 0.900f, 1.500f},
			               		{1.000f, 1.100f, 1.200f, -1.600f}
			               	});

			var r = new Matrix(new[,]
			                   	{
			                   		{0.62500f, -1.25000f, 0.62500f, 0.00000f},
			                   		{-18.12500f, 2.50000f, 9.37500f, -3.75000f},
			                   		{15.8854167f, -1.25000f, -8.4895833f, 3.854167f},
			                   		{-0.15625f, 0.00000f, 0.46875f, -0.31250f}
			                   	});

			Assert.IsTrue(Matrix.AreEqual(m.Invert(), r, _tolerance));

			// test inverse multiplied against original is the identity
			m.SetRow(0, -1.1F, 2.6F, -7.1F, 2.2F);
			m.SetRow(1, 4.6F, -3.7F, 9.1F, 6.9F);
			m.SetRow(2, 4.1F, -3.1F, 7.7F, 7.1F);
			m.SetRow(3, -9.9F, 0.2F, 4.3F, 5.5F);

			Assert.IsTrue(Matrix.AreEqual(m*m.Invert(), Matrix.GetIdentity(4), _tolerance));
			Assert.IsTrue(Matrix.AreEqual(m.Invert()*m, Matrix.GetIdentity(4), _tolerance));

			// test non-invertible
			m.SetRow(0, 1, 0, 0, 0);
			m.SetRow(1, 0, 1, 0, 0);
			m.SetRow(2, 0, 0, 1, 0);
			m.SetRow(3, 0, 0, 5, 0);

			try
			{
				m.Invert();
				Assert.Fail("Expected an exception");
			}
			catch (ArgumentException) {}
		}
开发者ID:m-berkani,项目名称:ClearCanvas,代码行数:48,代码来源:MatrixTests.cs

示例3: TestInverse3

		public void TestInverse3()
		{
			// test identity inverse
			var m = Matrix.GetIdentity(3);

			Assert.IsTrue(Matrix.AreEqual(m.Invert(), new Matrix(new float[,] {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}})));

			// test a known inverse
			m = new Matrix(new[,]
			               	{
			               		{0.100f, 0.200f, 0.300f},
			               		{-0.400f, 0.500f, 0.600f},
			               		{0.700f, 0.800f, 0.900f}
			               	});

			var r = new Matrix(new[,]
			                   	{
			                   		{0.62500f, -1.25000f, 0.62500f},
			                   		{-16.25000f, 2.50000f, 3.75000f},
			                   		{13.95833f, -1.25000f, -2.70833f}
			                   	});

			Assert.IsTrue(Matrix.AreEqual(m.Invert(), r, _tolerance));

			// test inverse multiplied against original is the identity
			m.SetRow(0, -1.1F, 2.6F, -7.1F);
			m.SetRow(1, 4.6F, -3.7F, 9.1F);
			m.SetRow(2, 4.1F, -3.1F, 7.7F);

			Assert.IsTrue(Matrix.AreEqual(m*m.Invert(), Matrix.GetIdentity(3), _tolerance));
			Assert.IsTrue(Matrix.AreEqual(m.Invert()*m, Matrix.GetIdentity(3), _tolerance));

			// test non-invertible
			m.SetRow(0, 1, 0, 0);
			m.SetRow(1, 0, 1, 0);
			m.SetRow(2, 0, 5, 0);

			try
			{
				m.Invert();
				Assert.Fail("Expected an exception");
			}
			catch (ArgumentException) {}
		}
开发者ID:m-berkani,项目名称:ClearCanvas,代码行数:44,代码来源:MatrixTests.cs

示例4: TestInverse2

		public void TestInverse2()
		{
			// test identity inverse
			var m = Matrix.GetIdentity(2);

			Assert.IsTrue(Matrix.AreEqual(m.Invert(), new Matrix(new float[,] {{1, 0}, {0, 1}})));

			// test a known inverse
			m = new Matrix(new[,]
			               	{
			               		{0.100f, 0.200f},
			               		{-0.400f, 0.500f}
			               	});

			var r = new Matrix(new[,]
			                   	{
			                   		{3.84615f, -1.53846f},
			                   		{3.07692f, 0.76923f}
			                   	});

			Assert.IsTrue(Matrix.AreEqual(m.Invert(), r, _tolerance));

			// test inverse multiplied against original is the identity
			m.SetRow(0, -1.1F, 2.6F);
			m.SetRow(1, 4.6F, -3.7F);

			Assert.IsTrue(Matrix.AreEqual(m*m.Invert(), Matrix.GetIdentity(2), _tolerance));
			Assert.IsTrue(Matrix.AreEqual(m.Invert()*m, Matrix.GetIdentity(2), _tolerance));

			// test non-invertible
			m.SetRow(0, 1, 0);
			m.SetRow(1, 5, 0);

			try
			{
				m.Invert();
				Assert.Fail("Expected an exception");
			}
			catch (ArgumentException) {}
		}
开发者ID:m-berkani,项目名称:ClearCanvas,代码行数:40,代码来源:MatrixTests.cs

示例5: TestInverse1

		public void TestInverse1()
		{
			// test identity inverse
			var m = Matrix.GetIdentity(1);

			Assert.IsTrue(Matrix.AreEqual(m.Invert(), new Matrix(new float[,] {{1}})));

			// test a known inverse
			m = new Matrix(new[,]
			               	{
			               		{0.100f}
			               	});

			var r = new Matrix(new[,]
			                   	{
			                   		{10.00f}
			                   	});

			Assert.IsTrue(Matrix.AreEqual(m.Invert(), r, _tolerance));

			// test inverse multiplied against original is the identity
			m.SetRow(0, -1.1F);

			Assert.IsTrue(Matrix.AreEqual(m*m.Invert(), Matrix.GetIdentity(1), _tolerance));
			Assert.IsTrue(Matrix.AreEqual(m.Invert()*m, Matrix.GetIdentity(1), _tolerance));

			// test non-invertible
			m.SetRow(0, 0);

			try
			{
				m.Invert();
				Assert.Fail("Expected an exception");
			}
			catch (ArgumentException) {}
		}
开发者ID:m-berkani,项目名称:ClearCanvas,代码行数:36,代码来源:MatrixTests.cs

示例6: TestInverse

		public void TestInverse()
		{
			try
			{
				var m = new Matrix(3, 2);
				m.Invert();
				Assert.Fail("Expected an exception");
			}
			catch (ArgumentException) {}

			try
			{
				var m = Matrix.GetIdentity(5);
				m.Invert();
				Assert.Fail("Expected an exception");
			}
			catch (NotImplementedException) {}
		}
开发者ID:m-berkani,项目名称:ClearCanvas,代码行数:18,代码来源:MatrixTests.cs

示例7: IntersectPlane

        public Vector2 IntersectPlane(Plane plane, Vector2 relativeMousePos)
        {
            // Relative screen position.
            float xRayView = relativeMousePos.X / Projection.M11;
            float yRayView = relativeMousePos.Y / Projection.M22;
            viewDirection.Normalize();
            Vector3 ray = viewDirection
                + rightVec * xRayView
                - upVec * yRayView;
            Vector4 pointVec = new Vector4(position - plane.Origin, 0);

            Matrix dirMat = new Matrix();
            Matrix test = Matrix.Translation(1, 1, 1);
            //var x = test.get_Rows(3);
            dirMat.set_Rows(0, new Vector4(plane.XAxis, 0));
            dirMat.set_Rows(1, new Vector4(plane.YAxis, 0));
            dirMat.set_Rows(2, new Vector4(-ray, 0));
            dirMat.set_Rows(3, Vector4.UnitW);
            dirMat.Invert();

            Vector4 res = Vector4.Transform(pointVec, dirMat);
            Vector2 xy = new Vector2(Vector4.Dot(dirMat.get_Rows(0), pointVec), Vector4.Dot(dirMat.get_Rows(1), pointVec));
            return new Vector2(res.X, res.Y);
        }
开发者ID:AnkeAnke,项目名称:FlowSharp,代码行数:24,代码来源:Camera.cs

示例8: PushTransform

        /// <summary>
        /// Pushes a matrix transformation.
        /// </summary>
        /// <param name="matrix">The matrix</param>
        /// <returns>A disposable used to undo the transformation.</returns>
        public IDisposable PushTransform(Matrix matrix)
        {
            _context.Transform(matrix.ToCairo());

            return Disposable.Create(() =>
            {
                _context.Transform(matrix.Invert().ToCairo());
            });
        }
开发者ID:tshcherban,项目名称:Perspex,代码行数:14,代码来源:DrawingContext.cs


注:本文中的System.Matrix.Invert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。