Ejemplo n.º 1
0
        public BCurve(int degree, List<Vector> controlPoints, BasisFunction basisFunction)
        {
            if (controlPoints.Count + 1 + degree != basisFunction.GetNKnots())
                throw new Exception("Number of control points + 1 + degree != n_knots");

            _mDegree = degree;
            _mControlPoints = controlPoints.ToArray();
            _mBasis = basisFunction;
            _mDimension = _mControlPoints[0].VectorDimension();
        }
Ejemplo n.º 2
0
        public BCurve(int degree, Vector[] controlPoints, BasisFunction basisFunction)
        {
            if (controlPoints.Length + degree + 1 != basisFunction.GetNKnots())
                throw new Exception("Number of control points + 1 + degree != n_knots");

            _mDegree = degree;
            _mControlPoints = controlPoints;
            _mBasis = basisFunction;
            _mDimension = _mControlPoints[0].VectorDimension();
        }
Ejemplo n.º 3
0
        public static void CentripetalMethod_createSplineByInterpolation(
            int degree, Vector[] interpolationPoints, ref BCurve result)
        {
            // NOTE: result is equal to null(ArgumentNullException)

            // Calculate interpolation parameters:
            double[] interpolationParameters = null;
            CentripetalMethod_calculateInterpolationParameters(interpolationPoints, ref interpolationParameters);

            // Calculate knots:
            double[] knots = null;
            CentripetalMethod_calculateKnots(degree, interpolationParameters, ref knots);

            // Create basis function:
            var basis = new BasisFunction(knots);

            // Number of control points:
            var nControlPoints = interpolationPoints.Length;

            // Create set of linearly independent equations:
            var matrixElements = new double[nControlPoints][];

            for (var i = 0; i < nControlPoints; i++)
            {
                matrixElements[i] = new double[nControlPoints];

                for (var j = 0; j < nControlPoints; j++)
                    matrixElements[i][j] = basis.Evaluate(j, degree, interpolationParameters[i]);
            }

            // Create matrix:
            var matrix = new BGeomMatrix(matrixElements);

            var dimension = interpolationPoints[0].VectorDimension();

            // Solve using Gaussian Elimination:
            var rhs = new Vector(nControlPoints);
            var controlPoints = new Vector[nControlPoints];

            for (var i = 0; i < dimension; i++)
            {
                // Fill the elements of the rhs:
                for (var j = 0; j < nControlPoints; j++)
                    rhs.Elements[j] = interpolationPoints[j].Elements[i];

                double[] gaussResult = null;

                LinearAlgebra.GaussianElimination(matrix, rhs, ref gaussResult);

                // Fill the control points
                for (var k = 0; k < nControlPoints; k++)
                {
                    if ( i == 0)
                        controlPoints[k] = new Vector(dimension);

                    controlPoints[k].Elements[i] = gaussResult[k];
                }
            }

            // Create spline:
            result = new BCurve(degree, controlPoints, basis);
        }
Ejemplo n.º 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            var knots = new List<double>
            {
                0.0,
                0.0,
                0.0,
                1.0,
                2.0,
                3.0,
                4.0,
                4.0,
                5.0,
                5.0,
                5.0
            };

            var controlPoints = new List<Vector>
            {
                new Vector(new[] {0.0, 0.0}),
                new Vector(new[] {1.0, 1.0}),
                new Vector(new[] {2.0, 0.0}),
                new Vector(new[] {3.0, -1.0}),
                new Vector(new[] {4.0, 0.0}),
                new Vector(new[] {5.0, 1.0}),
                new Vector(new[] {6.0, 0.0}),
                new Vector(new[] {7.0, -1.0})
            };

            var basis = new BasisFunction(knots);
            var curve = new BCurve(2, controlPoints, basis);

            _sessionCurve = curve;

            curve.Evaluate(2.5);

            // Testing gaussian elimination:
            var matrixElements = new List<List<double>>
            {
                new List<double>
                {
                    1,
                    -3,
                    1
                },

                new List<double>
                {
                    2,
                    -8,
                    8
                },

                new List<double>
                {
                    -6,
                    3,
                    -15
                }
            };

            var rhs = new Vector(new double[] { 4, -2, 9 });
            var matrix = new BGeomMatrix(matrixElements);

            double[] results = null;

            LinearAlgebra.GaussianElimination(matrix, rhs, ref results);

            // make straight line with points:
            var straightLine0 = new List<Vector>();

            for (var i = 0; i < 5; i++)
                straightLine0.Add(new Vector(new[] { i, i % 2.0 }));

            // Interpolate straight line
            var straightLine1 = new BCurve();

            GeomUtils.CentripetalMethod_createSplineByInterpolation(3, straightLine0.ToArray(), ref straightLine1);

            _sessionCurve = straightLine1;
        }