Пример #1
0
        private void showGraph()
        {
            Ugs = CurveTracer.Norm(Ugs);

            var multiplier = 100;
            var delta      = Ugs[6] - Ugs[5];
            var shift      = delta / multiplier;

            var size = (int)Math.Round((Math.Abs(Ugs[10] - Ugs[0])) / shift) + 1;
            var x    = new double[size];
            var y    = new double[size];
            var y1   = new double[size];
            var y2   = new double[size];
            var h2   = new double[size];
            var h3   = new double[size];

            for (var u = Ugs[0]; u < Ugs[10]; u += shift)
            {
                var i = (int)Math.Round(Math.Abs(Ugs[0] - u) / shift);
                x[i]  = u;
                y[i]  = CurveTracer.B(Ugs, k0, u, 0);
                y1[i] = CurveTracer.B(Ugs, k0, u, 1);
                y2[i] = CurveTracer.B(Ugs, k0, u, 2);
                h2[i] = y1[i] / (2 * y[i]);
                h3[i] = y2[i] / (2 * y[i]);
            }

            //var ko = new double[size];
            //for (var i=0 ; i < x.Length; i++ )
            //    ko[i] = y[i] + (1 / 4) * y2[i] + (1 / 16) * y2[i];

            var newH3x = new List <double>();
            var newH3y = new List <double>();

            for (var i = 0; i < x.Length; i++)
            {
                if (h3[i] > -k0.Max() && h3[i] < k0.Max())
                {
                    newH3y.Add(h3[i]);
                    newH3x.Add(x[i]);
                }
            }

            var newH2x = new List <double>();
            var newH2y = new List <double>();

            for (var i = 0; i < x.Length; i++)
            {
                if (h2[i] > -k0.Max() && h2[i] < k0.Max())
                {
                    newH2y.Add(h2[i]);
                    newH2x.Add(x[i]);
                }
            }

            double min    = double.MinValue;
            int    minPos = 0;

            for (var i = 0; i < x.Length; i++)
            {
                var value = y[i] - Math.Abs(h3[i]);
                if (value > min)
                {
                    min    = value;
                    minPos = i;
                }
            }

            var vertMinX = new double[size];
            var vertMinY = new double[size];

            for (var i = 0; i < x.Length; i++)
            {
                vertMinX[i] = x[minPos];
                vertMinY[i] = -k0.Max() + i * 2 * k0.Max() / size;
            }

            var funcs1  = new Func[] { new Func(x, y), new Func(newH3x.ToArray(), newH3y.ToArray()), new Func(vertMinX, vertMinY) };
            var bitmap1 = FuncTools.CreateBitmap(funcs1);

            FuncTools.FuncsToLines(bitmap1, delta, funcs1);
            FuncTools.AddAxis(bitmap1, delta, funcs1);
            FuncTools.AddLabels(bitmap1, delta, funcs1);
            FuncTools.AddTextInPhisicalCoords(bitmap1, new Coord(funcs1), x[minPos], y[minPos], string.Format("B0: {0:F2}", y[minPos]));
            FuncTools.AddTextInPhisicalCoords(bitmap1, new Coord(funcs1), x[minPos], h3[minPos], string.Format("H3:  {0:F4}", h3[minPos]));
            FuncTools.AddTextInPhisicalCoords(bitmap1, new Coord(funcs1), x[minPos], y[minPos] - 3, string.Format("Uзи: {0:F2} ,В", x[minPos]));

            pictureBox1.Image = bitmap1;

            var funcs2  = new Func[] { new Func(x, y), new Func(newH3x.ToArray(), newH3y.ToArray()), new Func(newH2x.ToArray(), newH2y.ToArray()), new Func(vertMinX, vertMinY) };
            var bitmap2 = FuncTools.CreateBitmap(funcs2);

            FuncTools.FuncsToLines(bitmap2, delta, funcs2);
            FuncTools.AddAxis(bitmap2, delta, funcs2);
            FuncTools.AddLabels(bitmap2, delta, funcs2);
            FuncTools.AddTextInPhisicalCoords(bitmap2, new Coord(funcs2), x[minPos], y[minPos], string.Format("B0: {0:F2}", y[minPos]));
            FuncTools.AddTextInPhisicalCoords(bitmap2, new Coord(funcs2), x[minPos], h3[minPos], string.Format("H3:  {0:F4}", h3[minPos]));
            FuncTools.AddTextInPhisicalCoords(bitmap2, new Coord(funcs2), x[minPos], y[minPos] - 3, string.Format("Uзи: {0:F2} ,В", x[minPos]));
            FuncTools.AddTextInPhisicalCoords(bitmap2, new Coord(funcs2), x[minPos], h2[minPos] + 2, string.Format("H2: {0:F3} ,В", h2[minPos]));

            pictureBox2.Image = bitmap2;

            listBox1.Items.Clear();
            listBox1.Items.Add(new MyListBoxItem(Color.Green, "██ - B0"));
            listBox1.Items.Add(new MyListBoxItem(Color.Red, "██ - H3"));
            listBox1.Items.Add(new MyListBoxItem(Color.Blue, "██ - Опт"));

            listBox2.Items.Clear();
            listBox2.Items.Add(new MyListBoxItem(Color.Green, "██ - B0"));
            listBox2.Items.Add(new MyListBoxItem(Color.Red, "██ - H3"));
            listBox2.Items.Add(new MyListBoxItem(Color.Blue, "██ - H2"));
            listBox2.Items.Add(new MyListBoxItem(Color.Brown, "██ - Опт"));
        }
Пример #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            var multiplier = 100;
            var delta      = Ugs[6] - Ugs[5];
            var shift      = delta / multiplier;

            var size = (int)Math.Round((Math.Abs(Ugs[10] - Ugs[0])) / shift) + 1;
            var x    = new double[size];
            var y    = new double[size];
            var y1   = new double[size];
            var y2   = new double[size];
            var h3   = new double[size];

            for (var u = Ugs[0]; u < Ugs[10]; u += shift)
            {
                var i = (int)Math.Round(Math.Abs(Ugs[0] - u) / shift);
                x[i]  = u;
                y[i]  = CurveTracer.B(Ugs, k0, u, 0);
                y1[i] = CurveTracer.B(Ugs, k0, u, 1);
                y2[i] = CurveTracer.B(Ugs, k0, u, 2);
                h3[i] = y2[i] / (2 * y[i]);
            }

            var newY = new List <double>();
            var newX = new List <double>();

            for (var i = 0; i < x.Length; i++)
            {
                //if (y1[i] > 0 && x[i] >= x[1 * multiplier] && x[i] <= x[x.Length - 1 * multiplier - 1])
                if (x[i] >= x[1 * multiplier] && x[i] <= x[x.Length - 1 * multiplier - 1])
                {
                    newY.Add(y1[i]);
                    newX.Add(x[i]);
                }
            }

            var newY2 = new List <double>();
            var newX2 = new List <double>();

            for (var i = 0; i < x.Length; i++)
            {
                if (x[i] >= x[1 * multiplier] && x[i] <= x[x.Length - 1 * multiplier - 1])
                {
                    newY2.Add(y2[i]);
                    newX2.Add(x[i]);
                }
            }

            var newY3 = new List <double>();
            var newX3 = new List <double>();

            for (var i = 0; i < x.Length; i++)
            {
                if (x[i] >= x[1 * multiplier] && x[i] <= x[x.Length - 1 * multiplier - 1])
                {
                    newY3.Add(h3[i]);
                    newX3.Add(x[i]);
                }
            }

            pictureBox1.Image = (new MyImage(FuncTools.FuncsToBytes(delta, new Func(newX.ToArray(), newY.ToArray())))).Bitmap;
            pictureBox2.Image = (new MyImage(FuncTools.FuncsToBytes(delta, new Func(newX2.ToArray(), newY2.ToArray())))).Bitmap;
            pictureBox3.Image = (new MyImage(FuncTools.FuncsToBytes(delta, new Func(newX3.ToArray(), newY3.ToArray())))).Bitmap;
            pictureBox4.Image = (new MyImage(FuncTools.FuncsToBytes(delta, new Func(newX.ToArray(), newY.ToArray()), new Func(newX3.ToArray(), newY3.ToArray())))).Bitmap;

            xMin1.Text = newX.Min().ToString("F");
            xMax1.Text = newX.Max().ToString("F");
            yMin1.Text = newY.Min().ToString("F");
            yMax1.Text = newY.Max().ToString("F");

            xMin2.Text = newX2.Min().ToString("F");
            xMax2.Text = newX2.Max().ToString("F");
            yMin2.Text = newY2.Min().ToString("F");
            yMax2.Text = newY2.Max().ToString("F");

            xMin3.Text = newX3.Min().ToString("F");
            xMax3.Text = newX3.Max().ToString("F");
            yMin3.Text = newY3.Min().ToString("F");
            yMax3.Text = newY3.Max().ToString("F");

            xMin4.Text = Math.Min(newX.Min(), newX3.Min()).ToString("F");
            xMax4.Text = Math.Max(newX.Max(), newX3.Max()).ToString("F");
            yMin4.Text = Math.Min(newY.Min(), newY3.Min()).ToString("F");
            yMax4.Text = Math.Max(newY.Max(), newY3.Max()).ToString("F");
        }