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


C# DenseVector.Negate方法代码示例

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


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

示例1: Test_UndistortDerivatives

        public void Test_UndistortDerivatives()
        {
            Rational3RDModel model = new Rational3RDModel();
            model.InitialAspectEstimation = 1;
            model.InitialCenterEstimation = new Vector2(0.5, 0.5);
            model.InitParameters();

            double k1 = 0.1, k2 = 0.02, k3 = (0.78 * Math.Sqrt(2.0) - 2.0) / 11.0;
            model.Parameters[0] = k1;
            model.Parameters[1] = k2;
            model.Parameters[2] = k3;

            Vector2 realPoint = new Vector2(1, 1);

            double ru = 0.5 * Math.Sqrt(2.0);
            double distortedX = 0.5 * (1.0 + ru * model.Parameters[0]) /
                (1.0 + ru * model.Parameters[1] + ru * ru * model.Parameters[2]);

            Vector2 distortedPoint = new Vector2(distortedX + 0.5, distortedX + 0.5);

            model.P = distortedPoint;
            model.FullUpdate();
            Vector2 correctedPoint = model.Pf;

            // Test Pf
            Assert.IsTrue(correctedPoint.DistanceTo(realPoint) < 1e-8,
                "Rational3 model undistort_derivatives final point test failed");

            Vector2 pd = new Vector2(0.55, 0.55);
            double rd = 0.55 * Math.Sqrt(2.0);
            double a = 0.1 - (0.858 - 1.1 * Math.Sqrt(2.0)) / 11.0;
            double b = 1.0 - 0.011 * Math.Sqrt(2.0);
            double c = -rd;
            double delta = b * b - 4 * a * c;
            ru = -(b - Math.Sqrt(delta)) / (2 * a);
            Vector2 pu = new Vector2(pd.X * ru / rd, pd.Y * ru / rd);

            // Test Diff_Xd
            Vector<double> diff_x = new DenseVector(6);
            diff_x[0] = 0.0; // k1
            diff_x[1] = 0.0; // k2
            diff_x[2] = 0.0; // k3
            diff_x[3] = -1.0; // cx
            diff_x[4] = 0.0; // cy
            diff_x[5] = -pd.X; // sx

            Vector<double> diff_y = new DenseVector(6);
            diff_y[0] = 0.0; // k1
            diff_y[1] = 0.0; // k2
            diff_y[2] = 0.0; // k3
            diff_y[3] = 0.0; // cx
            diff_y[4] = -1.0; // cy
            diff_y[5] = 0.0; // sx

            Assert.IsTrue((diff_x - model.Diff_Xd).L2Norm() < 1e-8,
                "Rational3 model Diff_Xd test failed");

            // Test Diff_Rd
            Vector<double> diff_rd = new DenseVector(6);
            diff_rd[0] = 0.0; // k1
            diff_rd[1] = 0.0; // k2
            diff_rd[2] = 0.0; // k3
            diff_rd[3] = (pd.X / rd) * diff_x[3]; // cx
            diff_rd[4] = (pd.Y / rd) * diff_y[4]; // cy
            diff_rd[5] = (pd.X / rd) * diff_x[5]; // sx

            Assert.IsTrue((diff_rd - model.Diff_Rd).L2Norm() < 1e-8,
                "Rational3 model Diff_Rd test failed");

            // Test Diff_Ru
            Vector<double> diff_a = new DenseVector(6);
            diff_a[0] = 1.0; // k1
            diff_a[1] = 0.0; // k2
            diff_a[2] = -rd; // k3
            diff_a[3] = -k3 * diff_rd[3]; // cx
            diff_a[4] = -k3 * diff_rd[4]; // cy
            diff_a[5] = -k3 * diff_rd[5]; // sx

            Vector<double> diff_b = new DenseVector(6);
            diff_b[0] = 0.0; // k1
            diff_b[1] = -rd; // k2
            diff_b[2] = 0.0; // k3
            diff_b[3] = -k2 * diff_rd[3]; // cx
            diff_b[4] = -k2 * diff_rd[4]; // cy
            diff_b[5] = -k2 * diff_rd[5]; // sx

            Vector<double> diff_c = diff_rd.Negate();
            Vector<double> diff_delta = 2 * b * diff_b - 4 * (a * diff_c + c * diff_a);
            Vector<double> diff_ru =
                (a * (diff_b.Negate() + (0.5 / Math.Sqrt(delta)) * diff_delta) -
                diff_a * (-b + Math.Sqrt(delta))) / (2 * a * a);

            Assert.IsTrue((diff_ru - model.Diff_Ru).L2Norm() < 1e-8,
                "Rational3 model Diff_Ru test failed");

            // Test Diff_Xu
            Vector<double> diff_xu = diff_x * (ru / rd) +
                pd.X * (diff_ru * (1 / rd) - (ru / (rd * rd)) * diff_rd);

            Assert.IsTrue((diff_xu - model.Diff_Xu).L2Norm() < 1e-8,
//.........这里部分代码省略.........
开发者ID:KFlaga,项目名称:Cam3D,代码行数:101,代码来源:Rational3ModelTests.cs


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