コード例 #1
0
        public GlobalBSpline InteractiveGlobalBSpline(int degree, double[] knots, double[] referencePoints, double leftDerivation, double rightDerivation, bool containsServiceKnots)
        {
            var controlPointsAndAuxKnots =
                _globalBSplineEngine.GlobalControlPointsAndAuxiliaryKnots(degree, knots, referencePoints, leftDerivation, rightDerivation, containsServiceKnots);
            var spline = InteractiveGlobalBSpline(degree, controlPointsAndAuxKnots.Item2, controlPointsAndAuxKnots.Item1, referencePoints, true);

            spline.LeftDerivation  = leftDerivation;
            spline.RightDerivation = rightDerivation;

            Ellipse leftDerEll, rightDerEll;
            double  pax, pay;

            if (containsServiceKnots)
            {
                var auxKnot           = knots[degree] - DERIVATIVE_AUX_KNOT_DISTANCE;
                var auxReferencePoint = MathOperations.LinearFunction(auxKnot, knots[degree], referencePoints.First(), leftDerivation);

                pax        = TransformCoordinates.WorldAreaToPlotAreaX(auxKnot, _plotArea, _worldArea);
                pay        = TransformCoordinates.WorldAreaToPlotAreaY(auxReferencePoint, _plotArea, _worldArea);
                leftDerEll = _auxiliaryEngine.DrawEllipse(pax - W_DIV_2, pay - H_DIV_2, AUX_KNOT_COLOR3);

                auxKnot           = knots[degree + referencePoints.Length - 1] + DERIVATIVE_AUX_KNOT_DISTANCE;
                auxReferencePoint = MathOperations.LinearFunction(auxKnot, knots[degree + referencePoints.Length - 1], referencePoints.Last(), rightDerivation);

                pax         = TransformCoordinates.WorldAreaToPlotAreaX(auxKnot, _plotArea, _worldArea);
                pay         = TransformCoordinates.WorldAreaToPlotAreaY(auxReferencePoint, _plotArea, _worldArea);
                rightDerEll = _auxiliaryEngine.DrawEllipse(pax - W_DIV_2, pay - H_DIV_2, AUX_KNOT_COLOR3);
            }
            else
            {
                var auxKnot           = knots.First() - DERIVATIVE_AUX_KNOT_DISTANCE;
                var auxReferencePoint = MathOperations.LinearFunction(auxKnot, knots.First(), referencePoints.First(), leftDerivation);

                pax        = TransformCoordinates.WorldAreaToPlotAreaX(auxKnot, _plotArea, _worldArea);
                pay        = TransformCoordinates.WorldAreaToPlotAreaY(auxReferencePoint, _plotArea, _worldArea);
                leftDerEll = _auxiliaryEngine.DrawEllipse(pax - W_DIV_2, pay - H_DIV_2, AUX_KNOT_COLOR3);

                auxKnot           = knots.Last() + DERIVATIVE_AUX_KNOT_DISTANCE;
                auxReferencePoint = MathOperations.LinearFunction(auxKnot, knots.Last(), referencePoints.Last(), rightDerivation);

                pax         = TransformCoordinates.WorldAreaToPlotAreaX(auxKnot, _plotArea, _worldArea);
                pay         = TransformCoordinates.WorldAreaToPlotAreaY(auxReferencePoint, _plotArea, _worldArea);
                rightDerEll = _auxiliaryEngine.DrawEllipse(pax - W_DIV_2, pay - H_DIV_2, AUX_KNOT_COLOR3);
            }
            spline.LeftDerivationEllipse  = leftDerEll;
            spline.RightDerivationEllipse = rightDerEll;
            return(spline);
        }
コード例 #2
0
        private void DragGBSplineLeftDerivation(MouseEventArgs e)
        {
            var yCursorPosition = CursorPositionY(e);

            _selectedEllipse.SetValue(Canvas.TopProperty, yCursorPosition);

            var degree = _selectedGlobalBSpline.Degree;
            var yCursorPositionInWA = TransformCoordinates.PlotAreaToWorldAreaY(yCursorPosition + H_DIV_2, _plotArea, _worldArea);
            var xCursorPositionInWA = _selectedGlobalBSpline.Knots[degree] - SplineDrawer.DERIVATIVE_AUX_KNOT_DISTANCE;
            var xCursorPosition     = TransformCoordinates.WorldAreaToPlotAreaX(xCursorPositionInWA, _plotArea, _worldArea);

            _selectedGlobalBSpline.LeftDerivation = MathOperations.DirectionOfLinearFunction(xCursorPositionInWA, yCursorPositionInWA, _selectedGlobalBSpline.Knots[degree], _selectedGlobalBSpline.FunctionValues[0]);
            _dragInfoLabel.WriteAndSetCoordinates(_selectedGlobalBSpline.LeftDerivation, xCursorPositionInWA, yCursorPositionInWA, xCursorPosition + AVOID_CURSOR_X, yCursorPosition + H_DIV_2);
            _dragInfoLabel.Visibility = Visibility.Visible;

            _canvasUtilities.RefreshGlobalBSplineInCanvas(_selectedGlobalBSpline, canvas1, _engine);
        }
コード例 #3
0
        private void DragCSplineLeftDerivation(MouseEventArgs e)
        {
            var cursorPositionY = CursorPositionY(e);

            _selectedEllipse.SetValue(Canvas.TopProperty, cursorPositionY);


            var yCursorPositionInWA = TransformCoordinates.PlotAreaToWorldAreaY(cursorPositionY + H_DIV_2, _plotArea, _worldArea);
            var xCursorPositionInWA = _selectedClampedSpline.Knots[0] - SplineDrawer.DERIVATIVE_AUX_KNOT_DISTANCE;
            var xCursorPosition     = TransformCoordinates.WorldAreaToPlotAreaX(xCursorPositionInWA, _plotArea, _worldArea);

            _selectedClampedSpline.Derivations[0] = MathOperations.DirectionOfLinearFunction(xCursorPositionInWA, yCursorPositionInWA, _selectedClampedSpline.Knots[0], _selectedClampedSpline.ControlPoints[0]);
            _dragInfoLabel.WriteAndSetCoordinates(_selectedClampedSpline.Derivations[0], xCursorPositionInWA, yCursorPositionInWA, xCursorPosition + AVOID_CURSOR_X, cursorPositionY + H_DIV_2);
            _dragInfoLabel.Visibility = Visibility.Visible;

            _canvasUtilities.RefreshClampedSplineInCanvas(_selectedClampedSpline, canvas1, _engine);
            // }
        }
コード例 #4
0
        private void DragHSplineDerivation(MouseEventArgs e)
        {
            var yCursorPosition = CursorPositionY(e);

            _selectedEllipse.SetValue(Canvas.TopProperty, yCursorPosition);
            var yCursorPositionInWA = TransformCoordinates.PlotAreaToWorldAreaY(yCursorPosition, _plotArea, _worldArea);
            var xCursorPositionInWA = _selectedHermiteSpline.Knots[_changedPointIndex] - SplineDrawer.DERIVATIVE_AUX_KNOT_DISTANCE;

            _selectedHermiteSpline.Derivations[_changedPointIndex] =
                MathOperations.DirectionOfLinearFunction(xCursorPositionInWA, yCursorPositionInWA, _selectedHermiteSpline.Knots[_changedPointIndex], _selectedHermiteSpline.ControlPoints[_changedPointIndex]);

            var selectedKnotPositionInPA = TransformCoordinates.WorldAreaToPlotAreaX(_selectedHermiteSpline.Knots[_changedPointIndex], _plotArea, _worldArea);

            _dragInfoLabel.WriteAndSetCoordinates(_changedPointIndex, _selectedHermiteSpline.Derivations[_changedPointIndex], xCursorPositionInWA, yCursorPositionInWA, selectedKnotPositionInPA + AVOID_CURSOR_X, yCursorPosition + H_DIV_2);
            _dragInfoLabel.Visibility = Visibility.Visible;

            _canvasUtilities.RefreshHermiteSplineInCanvas(_selectedHermiteSpline, canvas1, _engine);
        }
コード例 #5
0
        internal Tuple <double[], double[]> GlobalControlPointsAndAuxiliaryKnots(int degree, double[] knots, double[] knotsFunctionValues, double leftDerivation, double rightDerivation, bool areKnotsService)
        {
            var matrixAndAuxKnots = GlobalBSplineMatrix(degree, knots, areKnotsService);
            var invertedMatrix    = MathOperations.MatrixInvert(matrixAndAuxKnots.Item1);
            var controlPoints     = MathOperations.MultiplyMatrixAndVector(invertedMatrix, knotsFunctionValues, leftDerivation, rightDerivation);


            //var knotsFunctionValuesMatrix = ArrayMyUtils.ArrayToMatrix(knotsFunctionValues);
            //var controlPointsMatrix = AlgebraOperations.MultiplyMatrices(invertedMatrix,knotsFunctionValuesMatrix);
            //double[] controlPoints = null;
            //try
            //{
            //    controlPoints = ArrayMyUtils.OneColumnMatrixToArray(controlPointsMatrix);
            //}
            //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[]>(controlPoints, matrixAndAuxKnots.Item2));
        }
コード例 #6
0
        public ClampedSpline InteractiveClampedSpline(double[] knots, double[] controlPoints, double leftDerivation, double rightDerivation)
        {
            var     ellipses = new List <Ellipse>(knots.Length);
            Ellipse leftDerEll, rightDerEll;

            double pax, pay;

            var auxKnot         = knots.First() - DERIVATIVE_AUX_KNOT_DISTANCE;
            var auxControlPoint = MathOperations.LinearFunction(auxKnot, knots.First(), controlPoints.First(), leftDerivation);

            pax        = TransformCoordinates.WorldAreaToPlotAreaX(auxKnot, _plotArea, _worldArea);
            pay        = TransformCoordinates.WorldAreaToPlotAreaY(auxControlPoint, _plotArea, _worldArea);
            leftDerEll = _auxiliaryEngine.DrawEllipse(pax - W_DIV_2, pay - H_DIV_2, AUX_KNOT_COLOR2);

            auxKnot         = knots.Last() + DERIVATIVE_AUX_KNOT_DISTANCE;
            auxControlPoint = MathOperations.LinearFunction(auxKnot, knots.Last(), controlPoints.Last(), rightDerivation);

            pax         = TransformCoordinates.WorldAreaToPlotAreaX(auxKnot, _plotArea, _worldArea);
            pay         = TransformCoordinates.WorldAreaToPlotAreaY(auxControlPoint, _plotArea, _worldArea);
            rightDerEll = _auxiliaryEngine.DrawEllipse(pax - W_DIV_2, pay - H_DIV_2, AUX_KNOT_COLOR2);

            for (int i = 0; i < knots.Length; i++)
            {
                pax = TransformCoordinates.WorldAreaToPlotAreaX(knots[i], _plotArea, _worldArea);
                pay = TransformCoordinates.WorldAreaToPlotAreaY(controlPoints[i], _plotArea, _worldArea);
                ellipses.Add(_auxiliaryEngine.DrawEllipse(pax - W_DIV_2, pay - H_DIV_2, KNOT_COLOR2));
            }

            // List<Line> linesOfSpline = HermiteSplineLines(knots,controlPoints);
            ClampedSpline spline = ClampedSpline(knots, controlPoints, leftDerivation, rightDerivation);

            spline.DragEllipses           = ellipses;
            spline.LeftDerivationEllipse  = leftDerEll;
            spline.RightDerivationEllipse = rightDerEll;
            return(spline);
        }
コード例 #7
0
        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));
        }