Пример #1
0
        public void Test_Abs()
        {
            GoldenSectionSearch gss = new GoldenSectionSearch {
                F = x => Math.Abs(x)
            };
            double minX = gss.Solve(-10, 1, 1e-5, false);

            Assert.AreEqual(0, minX, 1e-5);
        }
Пример #2
0
        public void Test_Sin()
        {
            GoldenSectionSearch gss = new GoldenSectionSearch {
                F = x => - Math.Sin(x)
            };
            double minX = gss.Solve(0, Math.PI, 1e-5, true);

            Assert.AreEqual(Math.PI / 2, minX, 1e-5);

            minX = gss.Solve(-0.1, Math.PI, 1e-5, true);
            Assert.AreEqual(Math.PI / 2, minX, 1e-5);
        }
Пример #3
0
        public void Test_WrongShape()
        {
            bool errorOcurred = false;

            try
            {
                GoldenSectionSearch gss = new GoldenSectionSearch {
                    F = x => Math.Sin(x)
                };
                gss.Solve(0, Math.PI, 1e-5, true);
            }
            catch (ApplicationException e)
            {
                errorOcurred = true;
            }
            Assert.IsTrue(errorOcurred);
        }
Пример #4
0
        public MarchingCubesResults GenerateI(double isoLevel, INterpolationAlgoritm interpolation)
        {
            if (interpolation == null)
            {
                interpolation = new GoldenSectionSearch(this.function, 0.005);
            }

            //AnalyzeCubes(cubes, isoLevel, interpolation);
            var results = new MarchingCubesResults()
            {
                Value = isoLevel
            };

            //foreach (var cube in cubes)
            //{
            //    results.Triangles.AddRange(GetTriangles(cube, isoLevel));
            //}

            return(results);
        }
Пример #5
0
        private void SetFunction(object parameter)
        {
            var function = FunctionsViewModel.SelectedItem;

            var step = function.Step;

            IinterpolationAlgoritm interpolation = new SimpleInterpolation();

            if (UseGoldenSection)
            {
                interpolation = new GoldenSectionSearch(function.Function);
            }

            //interpolation = new SimpleInterpolation(false);
            var marchingCubes = new MarchingCubes.Algoritms.MarchingCubes.MarchingCubesAlgorithm(function.Function, interpolation);
            var defaultSize   = 10;
            var region        = function.Region ?? new Region3D(0, defaultSize, 0, defaultSize, 0, defaultSize);
            var results       = marchingCubes.Generate(region, step, function.CountorLine);

            viewPort.Children.Remove(gridModel);
            var converter = new ModelsConverter();

            if (ShowGrid)
            {
                var grid = converter.RenderGrid(results.Grid, DrawVertexIndexes, null);
                viewPort.Children.Add(grid);

                gridModel = grid;
            }

            var model = converter.RenderMesh(results.Triangles, UseMeshNormals, ShowNormals, ShowTwoSided);

            viewPort.Children.Remove(meshModel);
            viewPort.Children.Add(model);
            meshModel = model;

            this.ShowFunctionsPanel = false;
        }