예제 #1
0
        public static double[] LeastSquareData(LineItem allPointsForBuilding)
        {
            double[] xData = GraphProcessing.CurveToArray(allPointsForBuilding, true);
            double[] yData = GraphProcessing.CurveToArray(allPointsForBuilding, false);
            var      ds    = new XYDataSet(xData, yData);
            double   k     = ds.Slope;
            double   b     = ds.YIntercept;

            return(new double[] { k, b });
        }
예제 #2
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);
        }