This article describes how to use matlab to establish and draw a spline. The example shows how to establish, evaluate, evaluate, and draw a spline.
Functions in the Matlab spline toolbox provide functions such as creation, operation, and drawing of splines;
1. Creation of Splines
The first step is to create a spline, curve or surface. Here, splines are divided into four categories based on the prefix:
Cs * Cubic Spline
Pp * piecewise polynomial spline, coefficient t ^ n
Sp * B-spline, coefficients of the Matrix Function B _n ^ I (t)
Rp * rational B-spline
Ii. spline operation
Spline operations include: function operations: evaluation, arithmetic operations, evaluation of points, etc.
Node operation: Mainly adjusts, sets, and modifies the number of nodes.
Iii. Simple Example
% Step1: load ctrlpoints and knots
Load data_example
% Step 2: create the spline
Sp = spmak (knots, ctrlpoints ');
Fnplt (sp, [knots (5), knots (42)]);
% Step 3: get points on the curve
Dt = knots (5): 3: knots (42 );
P = fnval (sp, dt );
Plot (p (1, :), p (2, :), '. G ')
% Step 4: get dir draw normals
Dp1 = fnder (sp );
Dp = fnval (dp1, dt );
Len = size (dt, 2 );
For I = 1: len
Dir = dp (:, I );
Scale = 1/sqrt (dir (1) ^ 2 + dir (2) ^ 2 );
Dir = dir * scale;
Plot ([p (1, I), p (1, I) + dir (2)], [p (2, I), p (2, I) -dir (1)], 'R ');
End
Sample result
Appendix: spline toolbox Functions
1. Cubic Splines
Csapi interpolation generates cubic Splines
Csape generates cubic splines with Given constraints
Csaps smoothly generate cubic Splines
Cscvn generates a cubic spline with interpolation parameters
Getcurve dynamically generates Cubic Spline
2. piecewise polynomial Splines
Ppmak generates piecewise polynomial Splines
Ppual calculates the piecewise polynomial spline value at the given point.
3. B-spline functions
B-spline function generated by spmak
Use spcrv to generate a uniform B-Spline Function
Spapi interpolation to generate B-spline functions
Spap2 uses the least squares method to generate B-spline functions
Spaps smooth the generated B-Spline
Configuration matrix for generating B-spline functions using spcol
4. rational splines
Rpmak generates rational splines
Rsmak generates rational splines
5. spline operation functions
Fnval calculates the spline function value at the given point.
Fmbrk returns a part of the spline function (such as breakpoint or coefficient)
Fncmb performs arithmetic operations on Splines
Fn2fm converts one form of splines into another form of Splines
Fnder evaluate the differentiation of splines (I .e. derivative)
Fndir evaluate the direction derivative of the spline function
Using fnint to calculate the points of A Spline Function
Fnjmp evaluate the function value at the break point
Fnplt line chart
Fnrfn inserts a breakpoint into the spline.
Fnlr generates the tarylor coefficient or Taylor Polynomial
6. spline endpoint and node processing functions
Augknt adds one or more nodes to the array of known nodes
Aveknt calculates the average value of node array elements.
Brk2knt adds node duplicates in the node Array
Knt2brk obtains the node and its recurrence from the node array.
Knt2mlt obtains the node and its recurrence from the node Array
Sorted calculates the number of elements in the node array in the array of the other node.
Aptknt obtains the node array used to generate the spline.
Newknt redistribution of piecewise polynomial Splines
Optknt: Find the optimal node Array Used for Interpolation
Chbpnt: Find the appropriate node array used to generate the spline
Original: http://hi.baidu.com/ck436/blog/item/ffd71c4ceba65af4d72afc82.html