示例#1
0
        private void runMethod_DoWork(object sender, DoWorkEventArgs e)
        {
            Func <double, double> func = x => Double.Parse(textBoxA.Text) * Math.Cos(Double.Parse(textBoxB.Text) * x)
                                         + Double.Parse(textBoxC.Text) * Math.Sin(Double.Parse(textBoxD.Text) * x);
            Method method = null;

            runMethod.ReportProgress((int)status + 10);

            var xLeft    = Double.Parse(textBoxXBegin.Text);
            var xRight   = Double.Parse(textBoxXEnd.Text);
            var maxSteps = int.Parse(textBoxMaxStepCount.Text);
            var _e       = Double.Parse(textBoxE.Text);

            if (perspective == bruteForce)
            {
                method = new Brute(func, xLeft, xRight, maxSteps, _e);
            }
            else
            {
                var r = Double.Parse(textBoxR.Text);
                if (perspective == piacovsky)
                {
                    method = new Piavsky(func, xLeft, xRight, maxSteps, _e, r);
                }
                if (perspective == strongin)
                {
                    method = new Strongin(func, xLeft, xRight, maxSteps, _e, r);
                }
            }
            runMethod.ReportProgress((int)status + 10);

            var report = method.solve(runMethod);

            status = 60;

            FElem elem = new FElem();

            elem.function = func;
            elem.xLeft    = xLeft;
            elem.xRight   = xRight;

            if (!runMethod.CancellationPending)
            {
                GraphProcessing gp = new GraphProcessing();
                perspective.methodInfo.graphControl.GraphPane.CurveList.Clear();
                gp.drawFunction(perspective.methodInfo.graphControl, ref elem, perspective.colorLine, runMethod);
                perspective.funcInfo = elem;

                perspective.curZoomBorder = new curZoom()
                {
                    xMin = perspective.funcInfo.xMin,
                    xMax = perspective.funcInfo.xMax,
                    yMin = perspective.funcInfo.yMin,
                    yMax = perspective.funcInfo.yMax
                };

                perspective.methodInfo.report = report;
                perspective.a            = Double.Parse(textBoxA.Text);
                perspective.b            = Double.Parse(textBoxB.Text);
                perspective.c            = Double.Parse(textBoxC.Text);
                perspective.d            = Double.Parse(textBoxD.Text);
                perspective.xLeft        = xLeft;
                perspective.xRight       = xRight;
                perspective.maxStepCount = maxSteps;
                perspective.e            = _e;
                if (perspective.withR)
                {
                    perspective.r = Double.Parse(textBoxR.Text);
                }
            }
        }
示例#2
0
        public void drawFunction(ZedGraphControl zgControl, ref FElem elem, Color lineColor, BackgroundWorker worker)
        {
            var           pane   = zgControl.GraphPane;
            var           w      = zgControl.Width;
            var           h      = zgControl.Height;
            PointPairList ppList = new PointPairList();

            var step = (elem.xRight - elem.xLeft) / w;

            var yLeft  = elem.function(elem.xLeft);
            var yRight = elem.function(elem.xRight);

            elem.yMin = yLeft > yRight ? yRight : yLeft;
            elem.yMax = yLeft > yRight ? yLeft : yRight;

            for (double i = elem.xLeft; i < elem.xRight; i += step)
            {
                var progress = (int)((i - elem.xLeft) / (elem.xRight - elem.xLeft) * 100);
                worker.ReportProgress(progress);
                if (worker.CancellationPending)
                {
                    return;
                }
                var curY = elem.function(i);
                if (curY < elem.yMin)
                {
                    elem.yMin = curY;
                }
                if (curY > elem.yMax)
                {
                    elem.yMax = curY;
                }
                ppList.Add(new PointPair(i, curY));
            }

            var curve = pane.AddCurve("", ppList, lineColor, ZedGraph.SymbolType.None);

            curve.Line.Width = 4.0f;

            var rX = elem.xRight - elem.xLeft;
            var rY = elem.yMax - elem.yMin;

            elem.xMin = elem.xLeft;
            elem.xMax = elem.xRight;

            pane.XAxis.Min = elem.xMin - rX * 0.1;
            pane.XAxis.Max = elem.xMax + rX * 0.1;
            pane.YAxis.Min = elem.yMin - rY * 0.1;
            pane.YAxis.Max = elem.yMax + rY * 0.1;

            //var line = new PointPairList();
            //line.Add(new PointPair(elem.xMin, 2 * elem.yMin - elem.yMax));
            //line.Add(new PointPair(elem.xMin, 2 * elem.yMax - elem.yMin));
            //curve = pane.AddCurve("", line, Color.FromArgb(((int)(((byte)(253)))), ((int)(((byte)(239)))), ((int)(((byte)(249))))), ZedGraph.SymbolType.None);
            //curve.Line.Style = System.Drawing.Drawing2D.DashStyle.Dash;
            //curve.Line.Width = 0.01f;
            //
            //line.Clear();
            //line.Add(new PointPair(elem.xMax, 2 * elem.yMin - elem.yMax));
            //line.Add(new PointPair(elem.xMax, 2 * elem.yMax - elem.yMin));
            //curve = pane.AddCurve("", line, Color.FromArgb(((int)(((byte)(253)))), ((int)(((byte)(239)))), ((int)(((byte)(249))))), ZedGraph.SymbolType.None);
            //curve.Line.Style = System.Drawing.Drawing2D.DashStyle.Dash;
            //curve.Line.Width = 0.01f;

            zgControl.AxisChange();
            zgControl.Invalidate();
        }