public DerivateForm(MainProgram form)
        {
            this.form = form;
            InitializeComponent();
            GraphProcessing.CreateGraph(firstDerivative, "Первая производная", "X", "Y'", 50, 5);
            GraphProcessing.CreateGraph(secondDerivative, "Вторая производная", "X", "Y''", 50, 5);
            firstDerivative.Tag  = 5;
            secondDerivative.Tag = 5;
            LineItem curve = null;

            form.buttons.Add(GraphProcessing.CreateCurve(ref curve, form.CurvesDropDownButton, firstDerivative, "Первая производная", Color.Red, 6, SymbolType.Circle, Color.Red));
            curve.Tag = 5;
            GraphProcessing.DerivativeGraph(form.getCurve, ref curve);
            LineItem curve2 = null;

            form.buttons.Add(GraphProcessing.CreateCurve(ref curve2, form.CurvesDropDownButton, secondDerivative, "Вторая производная", Color.Blue, 6, SymbolType.Circle, Color.Blue));
            GraphProcessing.SecondDerivativeGraph(curve, ref curve2);
            curve2.Tag = 5;

            LineItem movingAverage = null;

            form.buttons.Add(GraphProcessing.CreateCurve(ref movingAverage, form.CurvesDropDownButton, firstDerivative, "Первая производная 2", Color.Cyan, 6, SymbolType.Circle, Color.Red));
            GraphProcessing.DerivativeGraph(form.processedCurve, ref movingAverage);
            movingAverage.Tag = 5;
            LineItem movingAverageTemp = new LineItem("temp");

            LineItem movingAverage2 = null;

            form.buttons.Add(GraphProcessing.CreateCurve(ref movingAverage2, form.CurvesDropDownButton, secondDerivative, "Вторая производная 2", Color.Cyan, 6, SymbolType.Circle, Color.Red));
            movingAverage2.Tag = 5;
            GraphProcessing.DerivativeGraph(form.processedCurve2, ref movingAverageTemp);
            GraphProcessing.SecondDerivativeGraph(movingAverageTemp, ref movingAverage2);
            GraphProcessing.UpdateGraph(firstDerivative);
            GraphProcessing.UpdateGraph(secondDerivative);
        }
Exemple #2
0
        public static void zeroTwoSigma1(LineItem originalCurve, PointPair p2, LineItem LineCurve, LineItem curved2, MainProgram form)
        {
            LineItem curve1 = null;
            LineItem curve2 = null;

            form.buttons.Add(GraphProcessing.CreateCurve(ref curve1, form.CurvesDropDownButton, form.ZGCInstance, "Параллель 1", Color.DarkCyan, 2, SymbolType.Default, Color.DarkCyan));
            curve1 = LineCurve;
            form.buttons.Add(GraphProcessing.CreateCurve(ref curve2, form.CurvesDropDownButton, form.ZGCInstance, "Параллель 2", Color.DarkCyan, 2, SymbolType.Default, Color.DarkCyan));
            //int max = 0;
            //for (int i = 0; i < originalCurve.Points.Count; i++) if (originalCurve.Points[i].X > max) max = (int)originalCurve.Points[i].X;
            //double average = 0;
            //for (int i = 0; i < curved2.Points.Count - 10; i++) average += Math.Abs(curved2[i].Y);
            //average /= curved2.Points.Count - 10;
            //int index = 0;
            //for (index = 0; index < curved2.Points.Count; index++) { if (curved2[index].Y > 10.0 * average) break; }
            double offSetY = originalCurve[originalCurve.Points.Count - 4].Y - p2.Y;
            double offSetX = originalCurve[originalCurve.Points.Count - 4].X - p2.X;

            for (int i = 0; i < LineCurve.Points.Count - 1; i++)
            {
                curve1.AddPoint(new PointPair(LineCurve.Points[i].X + offSetX, LineCurve.Points[i].Y += offSetY));
            }
            int offSetX2 = (int)Math.Round(0.98 * originalCurve.Points[originalCurve.Points.Count - 4].X);

            for (int i = 0; i < curve1.Points.Count; i++)
            {
                curve2.AddPoint(new PointPair(curve1.Points[i].X + offSetX2, curve1.Points[i].Y));
            }
        }
Exemple #3
0
        public static PointPair parallelLineSigma(double offSetCoef, MainProgram form, LineItem LineCurve, LineItem originalCurve, double distance, string name)
        {
            double   k1     = form.kCoef;
            double   b1     = (-offSetCoef * distance + form.bCoef);
            LineItem curve3 = new LineItem(name);

            form.buttons.Add(GraphProcessing.CreateCurve(ref curve3, form.CurvesDropDownButton, form.ZGCInstance, name, Color.Purple, 1, SymbolType.Default, Color.Purple));
            for (int i = 0; i < 1.5 * LineCurve[LineCurve.Points.Count - 1].X; i++)
            {
                if ((k1 * i + b1) > 0)
                {
                    curve3.AddPoint(new PointPair(i, k1 * i + b1));
                }
            }
            curve3.Tag = 1;
            bool      intersects = false;
            int       index1     = 1;
            PointPair temp       = null;

            while (index1 < originalCurve.Points.Count - 2 && !intersects)
            {
                PointPair point1 = originalCurve[index1 - 1];
                PointPair point2 = originalCurve[index1];
                temp = lineLineIntersection(point1, point2, k1, b1);
                if (temp.X >= point1.X && temp.X <= point2.X)
                {
                    if (temp.Y >= point1.Y && temp.Y <= point2.Y)
                    {
                        intersects = true;
                    }
                }
                index1++;
            }
            return(temp);
        }
Exemple #4
0
        public static void zeroTwoSigma2(LineItem originalCurve, PointPair p2, LineItem LineCurve, LineItem curved2, MainProgram form)
        {
            LineItem curve1 = null;
            LineItem curve2 = null;

            form.buttons.Add(GraphProcessing.CreateCurve(ref curve1, form.CurvesDropDownButton, form.ZGCInstance, "Паралелль 1", Color.DarkCyan, 4, SymbolType.Default, Color.DarkCyan));
            form.buttons.Add(GraphProcessing.CreateCurve(ref curve2, form.CurvesDropDownButton, form.ZGCInstance, "Паралелль 2", Color.DarkCyan, 4, SymbolType.Default, Color.DarkCyan));

            int max = 0;

            for (int i = 0; i < originalCurve.Points.Count; i++)
            {
                if (originalCurve.Points[i].X > max)
                {
                    max = (int)originalCurve.Points[i].X;
                }
            }
            double average = 0;

            for (int i = 0; i < curved2.Points.Count - 10; i++)
            {
                average += Math.Abs(curved2[i].Y);
            }
            average /= curved2.Points.Count - 10;
            int index = 0;

            for (index = 0; index < curved2.Points.Count; index++)
            {
                if (curved2[index].Y > 10.0 * average)
                {
                    break;
                }
            }
            double offSetY = originalCurve[index].Y - p2.Y;
            double offSetX = originalCurve[index].X - p2.X;

            for (int i = 0; i < LineCurve.Points.Count - 1; i++)
            {
                double x = LineCurve.Points[i].X - offSetX;
                double y = LineCurve.Points[i].Y + offSetY;
                curve1.AddPoint(new PointPair(x, y));
            }
            int offSetX2 = (int)Math.Round(0.8 * curve1.Points[0].X);

            for (int i = 0; i < curve1.Points.Count; i++)
            {
                curve2.AddPoint(new PointPair(curve1.Points[i].X - offSetX2, curve1.Points[i].Y));
            }
            curve1.Tag = 5;
            curve2.Tag = 5;
        }
        private void accept_Click(object sender, EventArgs e)
        {
            aproximateLinearCurve = null;
            GraphProcessing.RemoveLine(MNK_NAME, form);
            GraphProcessing.RemoveLine(MNK_NAME, form);
            GraphProcessing.RemoveLine(REG_NAME, form);

            GraphProcessing.UpdateGraph(form.ZGCInstance);
            if (form.SelectionCurveBegin != null && form.SelectionCurveEnd != null)
            {
                int index = form.ZGCInstance.GraphPane.CurveList.IndexOf(MNK_NAME);
                if (index >= 0)
                {
                    form.ZGCInstance.GraphPane.CurveList.RemoveAt(index);
                    DynamicToolStripButton tempBtn = null;
                    for (int i = 0; i < form.buttons.Count; i++)
                    {
                        string test = form.buttons[i].curve.Label.Text;
                        if (test == MNK_NAME)
                        {
                            tempBtn = form.buttons[i]; break;
                        }
                    }
                    form.CurvesDropDownButton.DropDownItems.Remove(tempBtn.button); //ошибка
                }


                PointPairList tempPointPair = (PointPairList)form.getCurve.Points;
                double        beginX        = tempPointPair.IndexOf(form.SelectionCurveBegin.Points[0]);
                double        endX          = tempPointPair.IndexOf(form.SelectionCurveEnd.Points[0]);
                int           begin         = (int)Math.Min(beginX, endX);
                int           end           = (int)Math.Max(beginX, endX);
                LineItem      temp          = new LineItem("tempCurve");
                temp.Tag = 5;

                if (form.getCurve != null)
                {
                    if (leastSquaresMode)
                    {
                        for (int i = begin; i < end; i++)
                        {
                            temp.AddPoint(form.getCurve.Points[i]);
                        }
                        begin = (int)form.getCurve.Points[begin].X;
                        end   = (int)form.getCurve.Points[end].X;

                        form.buttons.Add(GraphProcessing.CreateCurve(ref aproximateLinearCurve, form.CurvesDropDownButton, form.ZGCInstance, MNK_NAME, Color.Green, 2, SymbolType.Default, Color.Green));
                        aproximateLinearCurve.Tag = 2;
                        double[] data = MyMath.leastSquaresBuild(begin, end, temp, ref aproximateLinearCurve, form);
                        form.kCoef = data[0];
                        form.bCoef = data[1];
                        form.ZGCInstance.Refresh();
                        GraphProcessing.UpdateGraph(form.ZGCInstance);

                        form.AproximateLinearCurve = aproximateLinearCurve;
                    }
                    if (regularMode)
                    {
                        aproximateLinearCurve = null;
                        double x1 = form.getCurve.Points[begin].X;
                        double y1 = form.getCurve.Points[begin].Y;

                        double x2 = form.getCurve.Points[end].X;
                        double y2 = form.getCurve.Points[end].Y;

                        // y= y1+(x-x1) (y2 - y1) / (x2-x1) ; y = k*(x-x1) + y1 = kx - (kx1 + y1)

                        double coef = (y2 - y1) / (x2 - x1);

                        form.buttons.Add(GraphProcessing.CreateCurve(ref aproximateLinearCurve, form.CurvesDropDownButton, form.ZGCInstance, REG_NAME, Color.DarkCyan, 6, SymbolType.Circle, Color.DarkCyan));
                        for (int i = (int)form.getCurve.Points[(int)begin].X; i < form.getCurve.Points[(int)end].X; i++)
                        {
                            aproximateLinearCurve.AddPoint(new PointPair(i, coef * (i - x1) + y1));
                        }
                        form.AproximateLinearCurve = aproximateLinearCurve;
                        GraphProcessing.UpdateGraph(form.ZGCInstance);
                        LineItem curveTemp = form.getCurve;
                        curveTemp.Tag             = 5;
                        aproximateLinearCurve.Tag = 2;
                        //MyMath.buildLine(form.secondDerivativeCurve, ref curveTemp, form);
                        form.getCurve = curveTemp;

                        GraphProcessing.UpdateGraph(form.ZGCInstance);
                        //y = (x-x1)*(y2-y1)/(x2-x1) + y1
                    }
                    isUsed = true;
                }

                //if (form.processedCurve != null) { form.ZGCInstance.GraphPane.CurveList.Remove(form.processedCurve); form.processedCurve = null; }
                //if (form.processedCurve2 != null) {  form.ZGCInstance.GraphPane.CurveList.Remove(form.processedCurve2); form.processedCurve2 = null; }
            }
            else
            {
                MessageBox.Show("Выберите две точки на прямой который будут использованы для построения прямой");
            }
            info.Text = form.getCurve.Points.Count.ToString();
        }
Exemple #6
0
        public static PointPair Sigma(LineItem originalCurve, PointPair p2, LineItem LineCurve, LineItem curved2, MainProgram form, bool zeroTwo, string name)
        {
            int index = originalCurve.Points.Count - 4;

            double[] xData   = GraphProcessing.CurveToArray(LineCurve, true);
            double[] yData   = GraphProcessing.CurveToArray(LineCurve, false);
            double   offSetY = originalCurve[index].Y - p2.Y;
            double   offSetX = originalCurve[index].X - p2.X;

            for (int i = 0; i < xData.Length; i++)
            {
                xData[i] += offSetX;
                yData[i] += offSetY;
            }

            var      ds    = new XYDataSet(xData, yData);
            double   k     = ds.Slope;
            double   b     = ds.YIntercept;
            LineItem curve = null;

            form.buttons.Add(GraphProcessing.CreateCurve(ref curve, form.CurvesDropDownButton, form.ZGCInstance, "Параллель 1", Color.DarkCyan, 1, SymbolType.Default, Color.DarkCyan));

            int curveLength = originalCurve.Points.Count;

            for (int i = 0; i < 1.1 * originalCurve.Points[curveLength - 5].X; i++)
            {
                if ((k * i + b) > 0)
                {
                    curve.AddPoint(new PointPair(i, k * i + b));
                }
            }
            // y = kx + b x = (y-b)/k; kx = b = > x = k/b
            double pos = Math.Abs(b / k);

            curve.AddPoint(new PointPair(pos, 0));

            int offSetX2 = (int)Math.Round(0.8 * curve.Points[0].X);

            LineItem curve2;

            curve2 = LineCurve.Clone();
            form.buttons.Add(GraphProcessing.CreateCurve(ref curve2, form.CurvesDropDownButton, form.ZGCInstance, "Параллель 2", Color.DarkCyan, 1, SymbolType.Default, Color.DarkCyan));
            for (int i = 0; i < LineCurve[0].X; i++)
            {
                if ((form.kCoef * i + form.bCoef) > 0)
                {
                    curve2.AddPoint(new PointPair(i, form.kCoef * i + form.bCoef));
                }
            }
            curve2.AddPoint(new PointPair(Math.Abs(form.bCoef / form.kCoef), 0));
            form.IntersectionPointBegin = curve[curve.Points.Count - 1].X;
            form.IntersectionPointEnd   = curve2[curve2.Points.Count - 1].X;
            curve.Tag  = 5;
            curve2.Tag = 1;

            // y = kx + b
            // y = k(x+0.02) + b
            // y = kx + 0.02k + b
            // yy = kx + (0.02k + b

            // -kx + y = b
            double    distance = Math.Abs(form.IntersectionPointEnd - form.IntersectionPointBegin);
            PointPair temp     = new PointPair(0, 0);

            if (zeroTwo)
            {
                temp = parallelLineSigma(0.02, form, LineCurve, originalCurve, distance, name);
            }
            else
            {
                temp = parallelLineSigma(0.05, form, LineCurve, originalCurve, distance, name);
            }

            GraphProcessing.UpdateGraph(form.ZGCInstance);
            return(temp);
        }