This Demonstration shows global Bspline curve fitting by the leastsquares method. Bsplines are a generalization of Bezier curves. In a Bspline, each control point is associated with a particular basis function. The implementation is fully described in the Details.
 Contributed by: Shutao Tang
 (Northwestern Polytechnical University, Xi'an City, China)
For definitions and details of the Bspline curve and Bspline basis function, see Related Links. Assume that and are given, where . We seek a degree nonrational curve , , (1) , , (2) the remaining are approximated in the leastsquares sense; that is, is a minimum with respect to the variables. Here, and are precomputed parameter values. , . . So is a scalarvalued function of the variables . Applying the standard technique of linear leastsquares fitting to minimize , set the derivatives with respect to the points, , to zero. The of these derivatives is , . . (1) Equation (1) is one linear equation in the unknowns . Letting yields the system of equations in unknowns, , where is the matrix of scalars , (2) is the vector of points , (3) . In order to set up equations (2) and (3), a knot vector with parameters is required. The can be computed using the following method (with , in each case): let , then let , then The placement of the knots should reflect the distribution of the . If , denote by the largest integer less than or equal to . We need a total of knots; there are internal knots and internal knot spans. . Then define the internal knots by , , , . (4) Equation (4) guarantees that every knot span contains at least one , and under this condition the matrix is positive definite and wellconditioned. [1] L. Piegl and W. Tiller, The NURBS Book, 2nd ed., Berlin: SpringerVerlag, 1997 pp. 410–413.
