Esempio n. 1
0
        public override void Draw()
        {
            if (finished)
            {
                var    Points = ApplyTransformations();
                int    n      = Points.Count - 1;
                double nFact  = Utils.MathUtils.Factorials[n];

                //Шаг
                double dt = 0.001;
                double t  = dt;

                double xPred = Points[0].X;
                double yPred = Points[0].Y;

                SelectBegin.X = (int)xPred;
                SelectBegin.Y = (int)yPred;
                SelectEnd.X   = (int)xPred;
                SelectEnd.Y   = (int)yPred;

                while (t < 1 + dt / 2)
                {
                    int    i = 0;
                    double xt = 0, yt = 0;
                    while (i <= n) // Было <=
                    {
                        //Интерполяционный полином Бернштейна
                        double J = Math.Pow(t, i) * Math.Pow(1 - t, n - i) * nFact / (Utils.MathUtils.Factorials[i] * Utils.MathUtils.Factorials[n - i]);
                        xt = xt + Points[i].X * J;
                        yt = yt + Points[i].Y * J;
                        i++;
                    }

                    Point Begin = new Point((int)xPred, (int)yPred);
                    Point End   = new Point((int)xt, (int)yt);

                    Line.Draw(Begin, End, FigureColor);
                    t    += dt;
                    xPred = xt; yPred = yt;

                    FindSelection(new Point((int)xPred, (int)yPred)); //Finds max&min points and sets selection accordingly to it.
                }
            }

            if (IsSelected)
            {
                DrawSelect();
            }
        }
Esempio n. 2
0
        public override void Draw()
        {
            var Points = ApplyTransformations();

            FindSelection(Points);
            for (int i = 0; i < Points.Count - 1; i++)
            {
                Line.Draw(Points[i], Points[i + 1], FigureColor);
            }
            Fill();
            if (IsSelected)
            {
                DrawSelect();
            }
        }
Esempio n. 3
0
        public override void DrawSetOp(List <int> List1, List <int> List2, int y)
        {
            List <double> XrLeft  = new List <double>();
            List <double> XrRight = new List <double>();

            //массив приращения пороговых функций
            double[] ThresholdIncr;
            //рабочий массив итоговых значений
            List <double[]> M = new List <double[]>();


            // Difference
            ThresholdIncr    = new double[1];
            ThresholdIncr[0] = 2;

            // Writing values to resulting array.
            int n = List1.Count();

            for (int i = 0; i < n; i += 2)
            {
                double[] k = { List1[i], 2 };
                M.Add(k);
                double[] l = { List1[i + 1], -2 };
                M.Add(l);
            }

            n = List2.Count();
            for (int i = 0; i < n; i += 2)
            {
                double[] k = { List2[i], 1 };
                M.Add(k);
                double[] l = { List2[i + 1], -1 };
                M.Add(l);
            }

            // Sorting array.
            Sort(M);

            double Q = 0, x, Qn;

            // If first element is right border...
            if (M[0][0] >= 0 && M[0][1] < 0)
            {
                // Add left border.
                XrLeft.Add(0);
                Q = -M[0][1];
            }

            // Adding values to left & right borders lists.
            for (int i = 0; i < M.Count; i++)
            {
                x  = M[i][0];
                Qn = Q + M[i][1];
                if (!Belong(Q, ThresholdIncr) && Belong(Qn, ThresholdIncr))
                {
                    XrLeft.Add(x);
                }

                if (Belong(Q, ThresholdIncr) && !Belong(Qn, ThresholdIncr))
                {
                    XrRight.Add(x);
                }

                Q = Qn;
            }

            if (Belong(Q, ThresholdIncr))
            {
                XrRight.Add(MainForm.bmp.Width);
            }

            // Writing line
            for (int i = 0; i < XrLeft.Count(); i++)
            {
                Line.Draw(new Point((int)XrLeft[i] + 1, y), new Point((int)XrRight[i], y), FigureColor);
                if (MaxY < y)
                {
                    MaxY = y;
                }
                if (MaxX < XrRight[XrRight.Count - 1])
                {
                    MaxX = (int)XrRight[XrRight.Count - 1];
                }
                if (MinY > y)
                {
                    MinY = y;
                }
                if (MinX > XrLeft[0])
                {
                    MinX = (int)XrLeft[0];
                }
            }
        }
Esempio n. 4
0
        public override void DrawSetOp(List <int> List1, List <int> List2, int y)
        {
            List <double> Xrl = new List <double>();
            List <double> Xrr = new List <double>();

            //массив приращения пороговых функций
            double[] ThresholdIncr;
            //рабочий массив итоговых значений
            List <double[]> M = new List <double[]>();


            // пересечение
            ThresholdIncr    = new double[1];
            ThresholdIncr[0] = 3;

            //переписываем значения в итоговый массив
            int n = List1.Count();

            for (int i = 0; i < n; i += 2)
            {
                double[] k = { List1[i], 2 };
                M.Add(k);
                double[] l = { List1[i + 1], -2 };
                M.Add(l);
            }

            n = List2.Count();
            for (int i = 0; i < n; i += 2)
            {
                double[] k = { List2[i], 1 };
                M.Add(k);
                double[] l = { List2[i + 1], -1 };
                M.Add(l);
            }

            //сортируем массив
            Sort(M);

            double Q = 0, x, Qn;

            //если первый элемент массива правая граница сегмента
            if (M[0][0] >= 0 && M[0][1] < 0)
            {
                //добавляем левую границу
                Xrl.Add(0);
                Q = -M[0][1];
            }

            //внос значений в списки левых и правых границ
            for (int i = 0; i < M.Count; i++)
            {
                x  = M[i][0];
                Qn = Q + M[i][1];
                if (!Belong(Q, ThresholdIncr) && Belong(Qn, ThresholdIncr))
                {
                    Xrl.Add(x);
                }

                if (Belong(Q, ThresholdIncr) && !Belong(Qn, ThresholdIncr))
                {
                    Xrr.Add(x);
                }

                Q = Qn;
            }

            if (Belong(Q, ThresholdIncr))
            {
                Xrr.Add(MainForm.bmp.Width);
            }

            //рисуем линию
            for (int i = 0; i < Xrl.Count(); i++)
            {
                Line.Draw(new Point((int)Xrl[i] + 1, y), new Point((int)Xrr[i], y), FigureColor);
                if (MaxY < y)
                {
                    MaxY = y;
                }
                if (MaxX < Xrr[Xrr.Count - 1])
                {
                    MaxX = (int)Xrr[Xrr.Count - 1];
                }
                if (MinY > y)
                {
                    MinY = y;
                }
                if (MinX > Xrl[0])
                {
                    MinX = (int)Xrl[0];
                }
            }
        }