Exemple #1
0
        internal double[] ClampedDerivations2(double[] controlPoints, double leftDerivation, double rightDerivation, double difference)
        {
            var r = controlPoints.Length;
            int K;
            int k0;

            if (r % 2 == 0)
            {
                K  = 3 / 2 + (r - 5) / 2;
                k0 = 2 + 2 * K;
            }
            else
            {
                K  = 1 + (r - 5) / 2;
                k0 = 3 + 2 * K;
            }

            var eqLS = ArrayMyUtils.CreateMatrix <double>(K);
            var eqPS = new double[K];

            if (r >= 5)
            {
                //var k = 0;
                //var i = k * 2;
                eqLS[0][0] = HET;
                //   eqPS[0] = (3*(controlPoints[0]-controlPoints[4]) -12*(controlPoints[1] - controlPoints[3]) + )
            }
            throw new NotImplementedException();
        }
        internal Tuple <double[], double[]> FunctionApproximationControlPointsAndAuxiliaryKnots(int degree, double[] pointsX, double[] pointsY, double[] knots, int[] knotsIndexes)
        {
            Tuple <double[][], double[]> matrixAndAuxKnots = FunctionApproximationMatrix(pointsX, knots, knotsIndexes, degree);

            double[][]        matrix          = matrixAndAuxKnots.Item1;
            double[][]        transposeMatrix = MathOperations.TransposeMatrix(matrix);
            double[][]        transposeAndMatrixMultiplicationInversion = MathOperations.MatrixInvert(MathOperations.MultiplyMatrices(transposeMatrix, matrix));
            double[][]        YMatrix = ArrayMyUtils.ArrayToMatrix(pointsY);
            double[][]        finalMatrix;
            double[]          finalMatrixAsArray;
            List <double[][]> matrixList = new List <double[][]>();

            matrixList.Add(transposeAndMatrixMultiplicationInversion);
            matrixList.Add(transposeMatrix);
            matrixList.Add(YMatrix);
            finalMatrix = MathOperations.MultiplyListOfMatrices(matrixList);
            try
            {
                finalMatrixAsArray = ArrayMyUtils.OneColumnMatrixToArray(finalMatrix);
            }
            catch (NumberOfMatrixColumnIsNotOneException)
            {
                System.Diagnostics.Debug.WriteLine("Matrix cannot be converted to an array because number of columns is not one");
                return(null);
            }

            return(new Tuple <double[], double[]>(finalMatrixAsArray, matrixAndAuxKnots.Item2));
        }
Exemple #3
0
        public ClampedSpline InteractiveClampedSpline(double leftKnot, double rightKnot, double[] controlPoints, double leftDerivation, double rightDerivation)
        {
            var length = controlPoints.Length;
            var knots  = ArrayMyUtils.GrowingArray(length, leftKnot, rightKnot);


            return(InteractiveClampedSpline(knots, controlPoints, leftDerivation, rightDerivation));
        }
Exemple #4
0
        private Tuple <double[][], double[]> GlobalBSplineMatrix(int degree, double[] knots, bool areKnotsService)
        {
            double[] serviceKnots;
            int      k;
            int      numberOfRowsAndColumns;
            int      numberOfRowsForLoop;

            if (areKnotsService)
            {
                serviceKnots           = knots;
                k                      = knots.Length - 2 * degree - 1;
                numberOfRowsAndColumns = k + 3;
                numberOfRowsForLoop    = k + 1;
            }
            else
            {
                serviceKnots           = BSpline.ServiceKnots(knots, degree, true);
                k                      = knots.Length - 1;
                numberOfRowsAndColumns = k + 3;
                numberOfRowsForLoop    = knots.Length;
            }



            bool isDegreeEven = degree % 2 == 0;
            var  iterations   = degree + 2;

            double[][] matrix = ArrayMyUtils.CreateMatrix <double>(numberOfRowsAndColumns, numberOfRowsAndColumns);

            //matrix[0][0] = Bell(knots[0], degree, serviceKnots, !isDegreeEven, 1, 0, iterations);
            //matrix[0][1] = Bell(knots[0], degree, serviceKnots, !isDegreeEven, 2, 1, iterations);
            //matrix[0][2] = Bell(knots[0], degree, serviceKnots, !isDegreeEven, 3, 2, iterations);
            for (int i = 0; i < numberOfRowsForLoop; i++)
            {
                matrix[i][i]     = Bell(serviceKnots[degree + i], degree, serviceKnots, !isDegreeEven, 1, i, degree + 2);
                matrix[i][i + 1] = Bell(serviceKnots[degree + i], degree, serviceKnots, !isDegreeEven, 2, i + 1, degree + 2);
                matrix[i][i + 2] = Bell(serviceKnots[degree + i], degree, serviceKnots, !isDegreeEven, 3, i + 2, degree + 2);
            }
            matrix[numberOfRowsAndColumns - 2][0] = BellDerivative(serviceKnots[degree], degree, serviceKnots, !isDegreeEven, 1, 0, iterations);
            matrix[numberOfRowsAndColumns - 2][1] = BellDerivative(serviceKnots[degree], degree, serviceKnots, !isDegreeEven, 2, 1, iterations);
            matrix[numberOfRowsAndColumns - 2][2] = BellDerivative(serviceKnots[degree], degree, serviceKnots, !isDegreeEven, 3, 2, iterations);

            matrix[numberOfRowsAndColumns - 1][numberOfRowsAndColumns - 3] = BellDerivative(serviceKnots[degree + numberOfRowsForLoop - 1], degree, serviceKnots, !isDegreeEven, 1, numberOfRowsAndColumns - 3, iterations);
            matrix[numberOfRowsAndColumns - 1][numberOfRowsAndColumns - 2] = BellDerivative(serviceKnots[degree + numberOfRowsForLoop - 1], degree, serviceKnots, !isDegreeEven, 2, numberOfRowsAndColumns - 2, iterations);
            matrix[numberOfRowsAndColumns - 1][numberOfRowsAndColumns - 1] = BellDerivative(serviceKnots[degree + numberOfRowsForLoop - 1], degree, serviceKnots, !isDegreeEven, 3, numberOfRowsAndColumns - 1, iterations);

            //System.Diagnostics.Debug.WriteLine("  ...BEG.......   ");
            //System.Diagnostics.Debug.WriteLine(matrix[numberOfRowsAndColumns - 2][0]);
            //System.Diagnostics.Debug.WriteLine(matrix[numberOfRowsAndColumns - 2][1]);
            //System.Diagnostics.Debug.WriteLine(matrix[numberOfRowsAndColumns - 2][2]);
            //System.Diagnostics.Debug.WriteLine("  ...MED.......   ");
            //System.Diagnostics.Debug.WriteLine(matrix[numberOfRowsAndColumns - 1][numberOfRowsAndColumns - 3]);
            //System.Diagnostics.Debug.WriteLine(matrix[numberOfRowsAndColumns - 1][numberOfRowsAndColumns - 2]);
            //System.Diagnostics.Debug.WriteLine(matrix[numberOfRowsAndColumns - 1][numberOfRowsAndColumns - 1]);
            //System.Diagnostics.Debug.WriteLine("  ...END.......   ");

            return(new Tuple <double[][], double[]>(matrix, serviceKnots));
        }
Exemple #5
0
        //internal double DualHermiteBasis(double x, double x0, double y0, double x1, double y1, double x2, double y2, double leftDerivation, double d2)
        //{

        //}

        // matica pre nezjodnocavny cspline
        //protected double[][] ClampedSplineMatrixForFiveControlPoints()
        //{
        //    var numberOfRowsAndColums = 3;
        //    // var derivations = new double[controlPoints.Length];

        //    double[][] matrix = ArrayMyUtils.CreateMatrix<double>(numberOfRowsAndColums, numberOfRowsAndColums);
        //    matrix[0][0] = 1;
        //    matrix[0][1] = 0.25;
        //    matrix[numberOfRowsAndColums - 1][numberOfRowsAndColums - 1] = 1;
        //    matrix[numberOfRowsAndColums - 1][numberOfRowsAndColums - 2] = 0.25;
        //    for (int i = 1; i < numberOfRowsAndColums - 1; i++)
        //    {
        //        matrix[i][i - 1] = 0.25;
        //        matrix[i][i] = 1;
        //        matrix[i][i + 1] = 0.25;
        //        //  leftSide[i] =
        //    }
        //    return matrix;
        //}


        //protected Tuple<double[][], double[]> ClampedSplineMatrixAndRightSide(double[] controlPoints, double leftDerivation, double rightDerivation)
        //{

        //    int numberOfEquations;
        //    double lastValueOnLeftSide;
        //    double lastValueOnRightSide;
        //    int numberOfControlPoints = controlPoints.Length;
        //    //int k0;
        //    if (numberOfControlPoints % 2 == 0)
        //    {
        //        numberOfEquations = (int)(0.5 + ((numberOfControlPoints - 5.0) / 2.0));
        //        lastValueOnLeftSide = 7.5;
        //        lastValueOnRightSide = (-2) * rightDerivation + 1.5 * controlPoints[numberOfControlPoints - 4]
        //            - 6 * controlPoints[numberOfControlPoints - 3] - 1.5 * controlPoints[numberOfControlPoints - 2]
        //            + 6 * controlPoints[numberOfControlPoints - 1];
        //        //k0 = (2 + 2*numberOfEquations);
        //    }
        //    else
        //    {
        //        numberOfEquations = (int)(1.0 + ((numberOfControlPoints - 5.0) / 2.0));
        //        lastValueOnLeftSide = 7;
        //        lastValueOnRightSide = 0.5 * rightDerivation + 1.5 * controlPoints[numberOfControlPoints - 4]
        //            - 6 * controlPoints[numberOfControlPoints - 3] + 6 * controlPoints[numberOfControlPoints - 2]
        //            - 1.5 * controlPoints[numberOfControlPoints - 1];
        //        //k0 = (3 + 2 * numberOfEquations);
        //    }

        //    var leftSide = ArrayMyUtils.CreateMatrix<double>(numberOfEquations);
        //    var rightSide = new double[numberOfEquations];

        //    leftSide[0][0] = 7;
        //    leftSide[0][1] = -0.5;
        //    leftSide[numberOfEquations - 1][numberOfEquations - 1] = lastValueOnLeftSide;
        //    leftSide[numberOfEquations - 1][numberOfEquations - 2] = -0.5;
        //    rightSide[0] = 1.5*controlPoints[0]-1.5*controlPoints[4]-6*controlPoints[1]+6*controlPoints[3]+0.5*leftDerivation;
        //    rightSide[numberOfEquations-1] = lastValueOnRightSide;

        //    for (int i = 1; i < numberOfEquations - 1; i++)
        //    {
        //        var k = 2*i;
        //        leftSide[i][i - 1] = -0.5;
        //        leftSide[i][i] = -7;
        //        leftSide[i][i + 1] = -0.5;
        //        rightSide[i] = 1.5 * controlPoints[k] - 1.5 * controlPoints[k + 4] - 6 * controlPoints[k + 1] + 6 * controlPoints[k + 3];
        //    }
        //    return Tuple.Create(leftSide, rightSide);

        //}

        protected double[] EvenDerivations(double[] controlPoints, double leftDerivation, double rightDerivation, double difference)
        {
            int    numberOfEquations;
            double lastValueOnLeftSide;
            double lastValueOnRightSide;
            int    numberOfControlPoints = controlPoints.Length;
            var    doubleDiff            = 2 * difference;

            if (numberOfControlPoints % 2 == 0)
            {
                numberOfEquations = (int)(1.5 + ((numberOfControlPoints - 5.0) / 2.0));
                var idx = (numberOfEquations - 1) * 2;
                lastValueOnLeftSide = HET + FEL;
                // lastValueOnRightSide = (-2) * rightDerivation + 1.5 * controlPoints[numberOfControlPoints - 4]
                //     - 6 * controlPoints[numberOfControlPoints - 3] - 1.5 * controlPoints[numberOfControlPoints - 2]
                //     + 6 * controlPoints[numberOfControlPoints - 1];
                // lastValueOnRightSide = (3 * (controlPoints[numberOfControlPoints - 4] - controlPoints[numberOfControlPoints - 2]) - 12 * (controlPoints[numberOfControlPoints - 3] - controlPoints[numberOfControlPoints - 1]) - 4* rightDerivation * difference) / (doubleDiff);
                lastValueOnRightSide = (3 * (controlPoints[idx] - controlPoints[idx + 2]) - 12 * (controlPoints[idx + 1] - controlPoints[idx + 3]) - 4 * rightDerivation * difference) / (doubleDiff);
            }
            else
            {
                numberOfEquations = (int)(1.0 + ((numberOfControlPoints - 5.0) / 2.0));
                var idx = (numberOfEquations - 1) * 2;
                lastValueOnLeftSide = HET;
                //lastValueOnRightSide = FEL * rightDerivation + 1.5 * controlPoints[numberOfControlPoints - 4]
                //    - 6 * controlPoints[numberOfControlPoints - 3] + 6 * controlPoints[numberOfControlPoints - 2]
                //    - 1.5 * controlPoints[numberOfControlPoints - 1];
                //lastValueOnRightSide = (3* (controlPoints[numberOfControlPoints-5] - controlPoints[numberOfControlPoints-1]) - 12 * (controlPoints[numberOfControlPoints-4] - controlPoints[numberOfControlPoints-2]) + rightDerivation * difference)/(doubleDiff);
                lastValueOnRightSide = (3 * (controlPoints[idx] - controlPoints[idx + 4]) - 12 * (controlPoints[idx + 1] - controlPoints[idx + 3]) + rightDerivation * difference) / (doubleDiff);
            }

            var lowerDiagonal = new double[numberOfEquations - 1];
            var mainDiagonal  = new double[numberOfEquations];
            var upperDiagonal = new double[numberOfEquations - 1];
            var rightSide     = new double[numberOfEquations];

            ArrayMyUtils.ArrayFill(lowerDiagonal, -FEL);
            Array.Copy(lowerDiagonal, upperDiagonal, upperDiagonal.Length - 1);
            ArrayMyUtils.ArrayFill(mainDiagonal, 7);
            mainDiagonal[mainDiagonal.Length - 1] = lastValueOnLeftSide;

            //rightSide[0] = 1.5*controlPoints[0]-1.5*controlPoints[4]-6*controlPoints[1]+6*controlPoints[3]+0.5*leftDerivation;
            rightSide[0] = (3 * (controlPoints[0] - controlPoints[4]) - 12 * (controlPoints[1] - controlPoints[3]) + leftDerivation * difference) / (doubleDiff);
            rightSide[numberOfEquations - 1] = lastValueOnRightSide;
            for (int i = 1; i < numberOfEquations - 1; i++)
            {
                var k = 2 * i;
                //leftSide[i][i - 1] = -0.5;
                //leftSide[i][i] = -7;
                //leftSide[i][i + 1] = -0.5;
                //rightSide[i] = 1.5 * controlPoints[k] - 1.5 * controlPoints[k + 4] - 6 * controlPoints[k + 1] + 6 * controlPoints[k + 3];
                rightSide[i] = (3 * (controlPoints[k] - controlPoints[k + 4]) - 12 * (controlPoints[k + 1] - controlPoints[k + 3])) / (doubleDiff);
            }

            return(MathOperations.SolveTridiagonalLinearEquationSystem(lowerDiagonal, mainDiagonal, upperDiagonal, rightSide));
        }
Exemple #6
0
        public BSpline RegressBSpline(int degree, double[] pointsX, double[] pointsY, double[] inputKnots)
        {
            var lines = new List <Line>();
            Tuple <double[], int[]>    knotsAndIndexesInPointsX;
            Tuple <double[], double[]> controlPointsAndAuxKnots;
            //double x = 0;
            //double y = 0;
            // var previous = new Point();
            //var current = new Point();
            int numberOfIntervals = inputKnots.Length - 1;

            knotsAndIndexesInPointsX = ArrayMyUtils.FindNearestValuesAndIndexes(pointsX, inputKnots);
            controlPointsAndAuxKnots = _bSplineEngine.FunctionApproximationControlPointsAndAuxiliaryKnots(degree, pointsX, pointsY, knotsAndIndexesInPointsX.Item1, knotsAndIndexesInPointsX.Item2);

            return(InteractiveBSpline(degree, controlPointsAndAuxKnots.Item1, controlPointsAndAuxKnots.Item2, true));
        }
Exemple #7
0
        private void canvas1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            // pri kliknuti si ulozime poziciu bodu
            //Point point = e.GetPosition(null);

            // pri double kliku pridavame objekty
            switch (e.ClickCount)
            {
            case 2:
                var cursorPosition     = CursorPosition(e);
                var cursorPositionInWA = TransformCoordinates.PlotAreaToWorldArea(cursorPosition, _plotArea, _worldArea);
                if (_selectedSpline != null)
                {
                    if (_selectedSpline is BSpline)
                    {
                        //_selectedBSpline = (BSpline) _selectedSpline;
                        //var knots = _selectedBSpline.KnotsWithoutServiceKnots().ToList();
                        //var idx = ArrayMyUtils.FindFirstIndexInSortedListWhichValueIsBiggerThanDesiredNumber(knots, cursorPositionInWA.X);
                        //if (idx != -1)
                        //{
                        //    knots.Insert(idx, cursorPositionInWA.X);
                        //}
                        //else
                        //{
                        //    knots.Add(cursorPositionInWA.X);
                        //}
                    }
                    else if (_selectedSpline is HermiteSpline)
                    {
                        _selectedHermiteSpline = (HermiteSpline)_selectedSpline;

                        for (int i = 0; i < _selectedHermiteSpline.LinesOfSpline.Count; i++)
                        {
                            var b = canvas1.Children.Remove(_selectedHermiteSpline.LinesOfSpline[i]);
                            if (!b)
                            {
                                haha.Text = "cannot remove line";
                            }
                            else
                            {
                                haha.Text = "line removed";
                            }
                        }

                        var knots         = _selectedHermiteSpline.Knots;
                        var controlPoints = _selectedHermiteSpline.ControlPoints;
                        var derivations   = _selectedHermiteSpline.Derivations;

                        var idx = ArrayMyUtils.FindFirstIndexInSortedListWhichValueIsBiggerThanDesiredNumber(knots, cursorPositionInWA.X);

                        if (idx != -1)
                        {
                            knots.Insert(idx, cursorPositionInWA.X);
                            controlPoints.Insert(idx, cursorPositionInWA.Y);
                            derivations.Insert(idx, 0);
                        }
                        else
                        {
                            knots.Add(cursorPositionInWA.X);
                            controlPoints.Add(cursorPositionInWA.Y);
                            derivations.Add(0);
                        }

                        //_selectedHermiteSpline.Knots = knots;
                        //_selectedHermiteSpline.ControlPoints = controlPoints;
                        //_selectedHermiteSpline.Derivations = derivations;
                        //_canvasUtilities.TotalRefreshHermiteSplineInCanvas(_selectedHermiteSpline, canvas1, _engine);
                        //_canvasUtilities.RemoveInCanvas(canvas1, _selectedHermiteSpline.LinesOfSpline);
                        //_canvasUtilities.RemoveInCanvas(canvas1, _selectedHermiteSpline.DerivationEllipses);
                        //_canvasUtilities.RemoveInCanvas(canvas1, _selectedHermiteSpline.DragEllipses);
                        //_hermiteSplineList.Remove(_selectedHermiteSpline);


                        var spline = _engine.InteractiveHermiteSpline(_selectedHermiteSpline.Knots.ToArray(), _selectedHermiteSpline.ControlPoints.ToArray(), _selectedHermiteSpline.Derivations.ToArray());
                        _hermiteSplineList.Add(spline);
                    }
                    else if (_selectedSpline is ClampedSpline)
                    {
                    }
                    else if (_selectedSpline is GlobalBSpline)
                    {
                    }
                }


                break;

            // hybanie s objektami
            case 1:
                var elements = VisualTreeHelper.FindElementsInHostCoordinates(e.GetPosition(null), (UIElement)sender) as List <UIElement>;
                for (int i = 0; i < elements.Count; i++)
                {
                    if (elements[i] is Ellipse)
                    {
                        _selectedEllipse = elements[i];

                        for (int j = 0; j < _bSplineList.Count; j++)
                        {
                            _selectedBSpline   = _bSplineList[j];
                            _selectedSpline    = _selectedBSpline;
                            _changedPointIndex = 0;
                            //if (_selectedBSpline.FunctionValues == null)
                            //{
                            var controlPointsCount = _selectedBSpline.ControlPoints.Count();
                            while (_changedPointIndex < controlPointsCount)
                            {
                                if (_selectedEllipse.Equals(_selectedBSpline.DragEllipses[_changedPointIndex]))
                                {
                                    haha.Text += " CP: " + _changedPointIndex + "   ";
                                    //_changedKnotPos = _changedPointIndex + 1;
                                    if (_changedPointIndex == 0)
                                    {
                                        _leftEllipseX  = -1;
                                        _rightEllipseX = (double)_selectedBSpline.DragEllipses[_changedPointIndex + 1].GetValue(Canvas.LeftProperty);
                                    }
                                    else if (_changedPointIndex == _selectedBSpline.DragEllipses.Count - 1)
                                    {
                                        _leftEllipseX  = (double)_selectedBSpline.DragEllipses[_changedPointIndex - 1].GetValue(Canvas.LeftProperty);
                                        _rightEllipseX = TransformCoordinates.WorldAreaToPlotAreaX(_selectedBSpline.Knots[_changedPointIndex + 2] - DEFAULT_REDRAWING_PRECISION, _plotArea, _worldArea);
                                    }
                                    else
                                    {
                                        _leftEllipseX  = (double)_selectedBSpline.DragEllipses[_changedPointIndex - 1].GetValue(Canvas.LeftProperty);
                                        _rightEllipseX = (double)_selectedBSpline.DragEllipses[_changedPointIndex + 1].GetValue(Canvas.LeftProperty);
                                    }
                                    SELECTED_ITEM_TYPE = SelectedDragItem.BSplineEllipse;
                                    _isMoving          = true;
                                    _changedKnotPos    = _changedPointIndex + 1;

                                    // _selectedSpline = _redrawedBSpline;
                                    haha.Text += " Knot: " + _changedKnotPos + "   ";
                                    //goto DRAG; // preskocime nasledujuci for-cyklus
                                    _engine.DrawPrecision = RedrawingPrecision;
                                    _selectedEllipse.CaptureMouse();
                                    return;
                                }
                                _changedPointIndex++;
                            }
                            //}
                            //else
                            //{
                        }

                        for (int j = 0; j < _globalBSplineList.Count; j++)
                        {
                            _selectedGlobalBSpline = _globalBSplineList[j];
                            _selectedSpline        = _selectedGlobalBSpline;
                            _changedPointIndex     = 0;
                            var redrawedGlobalBSplineCount = _selectedGlobalBSpline.ControlPoints.Count();

                            if (_selectedEllipse.Equals(_selectedGlobalBSpline.LeftDerivationEllipse))
                            {
                                SELECTED_ITEM_TYPE    = SelectedDragItem.GBSplineLeftDerEllipse;
                                _isMoving             = true;
                                _changedKnotPos       = _changedPointIndex;
                                _engine.DrawPrecision = RedrawingPrecision;
                                _selectedEllipse.CaptureMouse();
                                return;
                            }
                            else if (_selectedEllipse.Equals(_selectedGlobalBSpline.RightDerivationEllipse))
                            {
                                SELECTED_ITEM_TYPE    = SelectedDragItem.GBSplineRightDerEllipse;
                                _isMoving             = true;
                                _changedKnotPos       = _changedPointIndex;
                                _engine.DrawPrecision = RedrawingPrecision;
                                _selectedEllipse.CaptureMouse();
                                return;
                            }
                            else
                            {
                                while (_changedPointIndex < _selectedGlobalBSpline.FunctionValues.Count())
                                {
                                    if (_selectedEllipse.Equals(_selectedGlobalBSpline.DragEllipses[_changedPointIndex]))
                                    {
                                        //haha.Text += " CP: " + _changedPointIndex + "   ";
                                        SELECTED_ITEM_TYPE = SelectedDragItem.GBSplineEllipse;

                                        // _selectedSpline = _redrawedBSpline;
                                        // haha.Text += " Knot: " + _changedKnotPos + "   ";
                                        //  goto DRAG; // preskocime nasledujuci for-cyklus

                                        _isMoving             = true;
                                        _changedKnotPos       = _changedPointIndex;
                                        _engine.DrawPrecision = RedrawingPrecision;
                                        _selectedEllipse.CaptureMouse();
                                        return;
                                    }
                                    _changedPointIndex++;
                                }
                            }
                        }

                        for (int j = 0; j < _clampedSplineList.Count; j++)
                        {
                            _selectedClampedSpline = _clampedSplineList[j];
                            _selectedSpline        = _selectedClampedSpline;
                            int redrawedCSplineCount = _selectedClampedSpline.ControlPoints.Count();
                            _changedPointIndex = 0;
                            if (_selectedEllipse.Equals(_selectedClampedSpline.LeftDerivationEllipse))
                            {
                                SELECTED_ITEM_TYPE = SelectedDragItem.CSplineLeftDerEllipse;
                                _isMoving          = true;
                                //_selectedSpline = _redrawedHermiteSpline;
                                // goto DRAG;
                                _engine.DrawPrecision = RedrawingPrecision;
                                _selectedEllipse.CaptureMouse();
                                return;
                            }
                            else if (_selectedEllipse.Equals(_selectedClampedSpline.RightDerivationEllipse))
                            {
                                SELECTED_ITEM_TYPE = SelectedDragItem.CSplineRightDerEllipse;
                                _isMoving          = true;
                                //_selectedSpline = _redrawedHermiteSpline;
                                // goto DRAG;
                                _engine.DrawPrecision = RedrawingPrecision;
                                _selectedEllipse.CaptureMouse();
                                return;
                            }
                            else
                            {
                                while (_changedPointIndex < redrawedCSplineCount)
                                {
                                    if (_selectedEllipse.Equals(_selectedClampedSpline.DragEllipses[_changedPointIndex]))
                                    {
                                        //haha.Text += _changedPointIndex + "   ";

                                        SELECTED_ITEM_TYPE = SelectedDragItem.CSplineEllipse;
                                        _isMoving          = true;
                                        //_selectedSpline = _redrawedHermiteSpline;
                                        // goto DRAG;
                                        _engine.DrawPrecision = RedrawingPrecision;
                                        _selectedEllipse.CaptureMouse();
                                        return;
                                    }
                                    _changedPointIndex++;
                                    //   }
                                }
                            }
                        }

                        for (int j = 0; j < _hermiteSplineList.Count; j++)
                        {
                            _selectedHermiteSpline = _hermiteSplineList[j];
                            _selectedSpline        = _selectedHermiteSpline;
                            int redrawedHSplineControlPointsCount = _selectedHermiteSpline.ControlPoints.Count();
                            _changedPointIndex = 0;
                            while (_changedPointIndex < redrawedHSplineControlPointsCount)
                            {
                                if (_selectedEllipse.Equals(_selectedHermiteSpline.DragEllipses[_changedPointIndex]))
                                {
                                    haha.Text += _changedPointIndex + "   ";
                                    if (_changedPointIndex == 0)
                                    {
                                        _leftEllipseX  = -1;
                                        _rightEllipseX = (double)_selectedHermiteSpline.DragEllipses[_changedPointIndex + 1].GetValue(Canvas.LeftProperty);
                                    }
                                    else if (_changedPointIndex == redrawedHSplineControlPointsCount - 1)
                                    {
                                        _leftEllipseX  = (double)_selectedHermiteSpline.DragEllipses[_changedPointIndex - 1].GetValue(Canvas.LeftProperty);
                                        _rightEllipseX = -1;
                                    }
                                    else
                                    {
                                        _leftEllipseX  = (double)_selectedHermiteSpline.DragEllipses[_changedPointIndex - 1].GetValue(Canvas.LeftProperty);
                                        _rightEllipseX = (double)_selectedHermiteSpline.DragEllipses[_changedPointIndex + 1].GetValue(Canvas.LeftProperty);
                                    }
                                    SELECTED_ITEM_TYPE = SelectedDragItem.HSplineEllipse;
                                    _isMoving          = true;
                                    //_selectedSpline = _redrawedHermiteSpline;
                                    // goto DRAG;
                                    _engine.DrawPrecision = RedrawingPrecision;
                                    _selectedEllipse.CaptureMouse();
                                    return;
                                }
                                else if (_selectedEllipse.Equals(_selectedHermiteSpline.DerivationEllipses[_changedPointIndex]))
                                {
                                    SELECTED_ITEM_TYPE    = SelectedDragItem.HSplineDerEllipse;
                                    _isMoving             = true;
                                    _engine.DrawPrecision = RedrawingPrecision;
                                    _selectedEllipse.CaptureMouse();
                                    return;
                                }
                                _changedPointIndex++;
                                //   }
                            }
                        }


                        //DRAG:
                        //_selectedEllipse.CaptureMouse();
                    }
                }

                break;
            }
        }
        private Tuple <double[][], double[]> FunctionApproximationMatrix(double[] X, double[] XKnots, int[] XKnotsIndexes, int degree)
        {
            int numberOfRows    = X.Length;
            int numberOfColumns = XKnots.Length - 1 + degree;

            double[] auxXKnots;
            bool     isDegreeEven = degree % 2 == 0;

            double[][] matrix = ArrayMyUtils.CreateMatrix <double>(numberOfRows, numberOfColumns);
            auxXKnots = BSpline.ServiceKnots(XKnots, degree, true);

            int k = 0;

            //for (int i = 0; i < numberOfRows; i++)
            //{
            //    int kk = Math.Max(0, numberOfEquations-1);

            //    for (int j = 0; j < numberOfColumns; j++)
            //    {

            //        if(j>=kk & j<=kk+degree)
            //        {
            //            //if (j - kk + 1==2)
            //            //{
            //            //    Console.WriteLine("zacina debug");
            //            //}
            //            leftSide[i][j]=Bell(knots, knots[i], degree,!isDegreeEven, j-kk+1, j, degree+2);
            //        }else{
            //            leftSide[i][j]=0;
            //        }
            //    }
            //    if(i==XKnotsIndexes[numberOfEquations]){
            //        numberOfEquations++;
            //    }
            //}

            for (int i = 0; i < numberOfRows; i++)
            {
                int kk = Math.Max(0, k - 1);

                for (int j = 0; j < numberOfColumns; j++)
                {
                    if (j >= kk & j <= kk + degree)
                    {
                        //if (j - kk + 1==2)
                        //{
                        //    Console.WriteLine("zacina debug");
                        //}
                        matrix[numberOfRows - i - 1][numberOfColumns - j - 1] = Bell(X[i], degree, auxXKnots, !isDegreeEven, j - kk + 1, j, degree + 2);
                    }
                    else
                    {
                        matrix[numberOfRows - i - 1][numberOfColumns - j - 1] = 0;
                    }
                }
                if (k < XKnotsIndexes.Length && i == XKnotsIndexes[k])
                {
                    k++;
                }
            }

            return(new Tuple <double[][], double[]>(matrix, auxXKnots));
        }