コード例 #1
0
        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);
        }
コード例 #2
0
        //kostil
        public void removeBigValue()
        {
            var curve = form.getCurve;

            for (int i = 0; i < curve.Points.Count; i++)
            {
                if (curve.Points[i].Y > 6 * Math.Pow(10, 6))
                {
                    curve.RemovePoint(i);
                }
            }
            GraphProcessing.UpdateGraph(form.ZGCInstance);
        }
コード例 #3
0
 private void DynamicButton_Click(object sender, EventArgs e)
 {
     if (!button.Checked)
     {
         zgc.GraphPane.CurveList.Add(curve);
         zgc.GraphPane.CurveList.Draw(zgc.CreateGraphics(), zgc.GraphPane, 1.0f);
     }
     else
     {
         zgc.GraphPane.CurveList.Remove(curve);
     }
     GraphProcessing.UpdateGraph(zgc);
     button.Checked = !button.Checked;
 }
コード例 #4
0
        private void firstDerivative_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            double stepX = 10;//Math.Log10(Math.Abs(firstDerivative.ScrollMaxX - firstDerivative.ScrollMinX));
            double stepY = 1; Math.Log10(Math.Abs(firstDerivative.ScrollMaxY - firstDerivative.ScrollMinY));

            if (e.KeyCode == Keys.Up)
            {
                firstDerivative.ScrollMinY  += stepY;
                firstDerivative.ScrollMaxY  += stepY;
                secondDerivative.ScrollMinY += stepY;
                secondDerivative.ScrollMaxY += stepY;
            }


            if (e.KeyCode == Keys.Down)
            {
                firstDerivative.ScrollMinY  -= stepY;
                firstDerivative.ScrollMaxY  -= stepY;
                secondDerivative.ScrollMinY -= stepY;
                secondDerivative.ScrollMaxY -= stepY;;
            }

            if (e.KeyCode == Keys.Left)
            {
                firstDerivative.ScrollMinX  -= stepX;
                firstDerivative.ScrollMaxX  -= stepX;
                secondDerivative.ScrollMinX -= stepX;
                secondDerivative.ScrollMaxX -= stepX;
            }

            if (e.KeyCode == Keys.Right)
            {
                firstDerivative.ScrollMinX  += stepX;
                firstDerivative.ScrollMaxX  += stepX;
                secondDerivative.ScrollMinX += stepX;
                secondDerivative.ScrollMaxX += stepX;
            }
            GraphProcessing.UpdateGraph(firstDerivative);
            GraphProcessing.UpdateGraph(secondDerivative);
        }
コード例 #5
0
        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();
        }
コード例 #6
0
        private void button1_Click(object sender, EventArgs e)
        {
            bool   error = false;
            double aDimnesion = 0, bDimension = 0, originalLength = 0, endLength = 0, maxForce = 0;

            if (endLengthTB.ReadOnly)
            {
                if (double.TryParse(aDimTB.Text, out aDimnesion) && (double.TryParse(bDimTB.Text, out bDimension) | bDimTB.ReadOnly) && double.TryParse(startLength.Text, out originalLength))
                {
                    if (!form.Port.IsOpen)
                    {
                        try
                        {
                            form.Port.Open();
                        }
                        catch (System.UnauthorizedAccessException ex) { MessageBox.Show(ex.Message); error = true; }
                    }
                    if (!error)
                    {
                        form.aDim           = aDimnesion;
                        form.bDim           = bDimension;
                        form.originalLength = originalLength;
                        form.metalMarking   = markingTB.Text;
                        form.type           = typeCB.Text;

                        form.ZGCInstance.GraphPane.Title.Text = markingTB.Text;
                        this.Visible = false;

                        GraphProcessing.resetGraph(form);
                        form.subscribe();
                    }
                }
                else
                {
                    MessageBox.Show("Неверно введены параметры.");
                }
            }
            else
            {
                if (double.TryParse(endLengthTB.Text, out endLength) && double.TryParse(bDimTB.Text, out bDimension))
                {
                    if (form.ViewIsPressed)
                    {
                        form.readingInOneSession.RemoveAt(form.readingInOneSession.Count - 1);
                    }
                    double max = Double.MinValue;
                    for (int i = 0; i < form.getCurve.Points.Count; i++)
                    {
                        if (form.getCurve.Points[i].Y > max)
                        {
                            max = form.getCurve.Points[i].Y;
                        }
                    }
                    maxForce = max;



                    form.endLength      = Math.Round(endLength, 2);
                    form.originalLength = Math.Round(form.originalLength, 2);
                    form.maxForce       = (int)maxForce;

                    form.relativeExpansion  = 1;
                    form.tempTearResistance = 1;


                    form.stressFlow        = new int?[2];
                    form.forceAtStressFlow = new int?[2];
                    for (int i = 0; i < form.yieldPoints.Length; i++)
                    {
                        if (form.yieldPoints[i] != null)
                        {
                            form.forceAtStressFlow[i] = (int?)Math.Round((form.yieldPoints[i].Y));
                        }
                    }
                    form.relativeExpansion = Math.Abs(Math.Round((((form.endLength / form.originalLength) - 1) * 100), 1));
                    if (form.type == "Плоская")
                    {
                        form.aDim      = Math.Round(form.aDim, 2);
                        form.bDim      = Math.Round(form.bDim, 2);
                        form.totalArea = Math.Round(form.aDim * form.bDim, 2);
                        for (int i = 0; i < form.forceAtStressFlow.Length; i++)
                        {
                            if (form.forceAtStressFlow[i] != null)
                            {
                                form.stressFlow[i] = (int?)(form.forceAtStressFlow[i] / form.totalArea);
                            }
                        }
                        form.tempTearResistance = Math.Round(maxForce / form.totalArea);
                        form.readingInOneSession.Add(new Classes.ExperimentReading(form.metalMarking, form.aDim, form.bDim, form.totalArea, form.originalLength, form.endLength, form.maxForce, form.forceAtStressFlow, form.stressFlow, form.tempTearResistance, form.relativeExpansion, form.yieldPoints));
                    }
                    if (form.type == "Цилиндрическая")
                    {
                        form.bDim           = bDimension;
                        form.diameterAfter  = Math.Round(bDimension, 2);
                        form.diameterBefore = Math.Round(form.aDim, 2);
                        form.totalArea      = Math.Round(((Math.PI * form.diameterBefore * form.diameterBefore) / 4), 2);
                        for (int i = 0; i < form.forceAtStressFlow.Length; i++)
                        {
                            if (form.forceAtStressFlow[i] != null)
                            {
                                form.stressFlow[i] = (int?)(form.forceAtStressFlow[i] / form.totalArea);
                            }
                        }
                        form.tempTearResistance = Math.Round(maxForce / form.totalArea);

                        form.relativeNarrowing = 100 * Math.Abs(Math.Round(((((Math.PI * form.diameterAfter * form.diameterAfter) / 4) / form.totalArea)), 1));
                        form.readingInOneSession.Add(new Classes.ExperimentReading(form.metalMarking, form.aDim, form.bDim, form.totalArea, form.originalLength, form.endLength, form.maxForce, form.forceAtStressFlow, form.stressFlow, form.tempTearResistance, form.relativeExpansion, form.relativeNarrowing, form.yieldPoints));
                    }

                    int pos = form.ZGCInstance.GraphPane.CurveList.IndexOf("Точка 1");
                    if (pos > 0)
                    {
                        form.ZGCInstance.GraphPane.CurveList.RemoveAt(pos);
                    }

                    int pos2 = form.ZGCInstance.GraphPane.CurveList.IndexOf("Точка 2");
                    if (pos2 > 0)
                    {
                        form.ZGCInstance.GraphPane.CurveList.RemoveAt(pos2);
                    }



                    double coefOfDiv        = Math.Abs((form.originalLength - form.endLength) / (form.IntersectionPointEnd - form.IntersectionPointBegin));
                    double distance         = form.IntersectionPointEnd;
                    double distancePositive = form.originalLength;
                    foreach (LineItem elem in form.ZGCInstance.GraphPane.CurveList)
                    {
                        for (int i = 0; i < elem.Points.Count; i++)
                        {
                            elem[i].X -= distance;
                            elem[i].X *= coefOfDiv;
                            elem[i].X += distancePositive;
                            form.ZGCInstance.GraphPane.XAxis.Title.Text = "L, мм";
                        }
                    }
                    GraphProcessing.UpdateGraph(form.ZGCInstance);

                    //form.MinXValue = form.originalLength;
                    //form.MaxXValue = form.endLength;
                    //form.MinYValue = 0;
                    //int maxYValueLocal = Int32.MinValue;
                    //for (int i = 0; i < form.getCurve.Points.Count; i++) if (form.getCurve[i].Y > maxYValueLocal) maxYValueLocal =  (int) form.getCurve[i].Y;
                    //form.MaxYValue = 1.2* maxYValueLocal;

                    //form.ZGCInstance.GraphPane.YAxis.MajorGrid.DashOff = (float) form.MaxYValue/10;
                    //form.ZGCInstance.GraphPane.XAxis.MajorGrid.DashOff = (float)form.MaxXValue /10;
                    form.ZGCInstance.RestoreScale(form.ZGCInstance.GraphPane);
                    GraphProcessing.UpdateGraph(form.ZGCInstance);


                    try
                    {
                        Bitmap   imageOfGraph = form.ZGCInstance.GraphPane.GetImage();
                        Graphics g            = Graphics.FromImage(imageOfGraph);
                        Bitmap   temp         = imageOfGraph;
                        temp.Save(Parsing.CheckForDuplicateImage(form.savePath, form.savePath, form.GraphName), System.Drawing.Imaging.ImageFormat.Bmp);
                    }
                    catch (Exception ex) { MessageBox.Show(ex.ToString()); }

                    ShowDialogueBox(form);
                }
            }
        }
コード例 #7
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);
        }