def insert(x, tck, m=1, per=0): """Insert knots into a B-spline. Description: Given the knots and coefficients of a B-spline representation, create a new B-spline with a knot inserted m times at point x. This is a wrapper around the FORTRAN routine insert of FITPACK. Inputs: x (u) -- A 1-D point at which to insert a new knot(s). If tck was returned from splprep, then the parameter values, u should be given. tck -- A sequence of length 3 returned by splrep or splprep containg the knots, coefficients, and degree of the spline. m -- The number of times to insert the given knot (its multiplicity). per -- If non-zero, input spline is considered periodic. Outputs: tck tck -- (t,c,k) a tuple containing the vector of knots, the B-spline coefficients, and the degree of the new spline. Requirements: t(k+1) <= x <= t(n-k), where k is the degree of the spline. In case of a periodic spline (per != 0) there must be either at least k interior knots t(j) satisfying t(k+1)<t(j)<=x or at least k interior knots t(j) satisfying x<=t(j)<t(n-k). Notes: Based on algorithms from: Boehm W : Inserting new knots into b-spline curves. Computer Aided Design 12 (1980) 199-201. Dierckx P. : Curve and surface fitting with splines, Monographs on Numerical Analysis, Oxford University Press, 1993. """ t, c, k = tck try: c[0][0] parametric = True except: parametric = False if parametric: cc = [] for c_vals in c: tt, cc_val, kk = insert(x, [t, c_vals, k], m) cc.append(cc_val) return (tt, cc, kk) else: tt, cc, ier = _fitpack._insert(per, t, c, k, x, m) if ier == 10: raise ValueError, "Invalid input data" if ier: raise TypeError, "An error occurred" return (tt, cc, k)
def insert(x,tck,m=1,per=0): """Insert knots into a B-spline. Description: Given the knots and coefficients of a B-spline representation, create a new B-spline with a knot inserted m times at point x. This is a wrapper around the FORTRAN routine insert of FITPACK. Inputs: x (u) -- A 1-D point at which to insert a new knot(s). If tck was returned from splprep, then the parameter values, u should be given. tck -- A sequence of length 3 returned by splrep or splprep containg the knots, coefficients, and degree of the spline. m -- The number of times to insert the given knot (its multiplicity). per -- If non-zero, input spline is considered periodic. Outputs: tck tck -- (t,c,k) a tuple containing the vector of knots, the B-spline coefficients, and the degree of the new spline. Requirements: t(k+1) <= x <= t(n-k), where k is the degree of the spline. In case of a periodic spline (per != 0) there must be either at least k interior knots t(j) satisfying t(k+1)<t(j)<=x or at least k interior knots t(j) satisfying x<=t(j)<t(n-k). Notes: Based on algorithms from: Boehm W : Inserting new knots into b-spline curves. Computer Aided Design 12 (1980) 199-201. Dierckx P. : Curve and surface fitting with splines, Monographs on Numerical Analysis, Oxford University Press, 1993. """ t,c,k=tck try: c[0][0] parametric = True except: parametric = False if parametric: cc = [] for c_vals in c: tt, cc_val, kk = insert(x, [t, c_vals, k], m) cc.append(cc_val) return (tt, cc, kk) else: tt, cc, ier = _fitpack._insert(per, t, c, k, x, m) if ier==10: raise ValueError,"Invalid input data" if ier: raise TypeError,"An error occurred" return (tt, cc, k)
def insert(x,tck,m=1,per=0): """ Insert knots into a B-spline. Given the knots and coefficients of a B-spline representation, create a new B-spline with a knot inserted m times at point x. This is a wrapper around the FORTRAN routine insert of FITPACK. Parameters ---------- x (u) : array_like A 1-D point at which to insert a new knot(s). If `tck` was returned from `splprep`, then the parameter values, u should be given. tck : tuple A tuple (t,c,k) returned by `splrep` or `splprep` containing the vector of knots, the B-spline coefficients, and the degree of the spline. m : int, optional The number of times to insert the given knot (its multiplicity). Default is 1. per : int, optional If non-zero, input spline is considered periodic. Returns ------- tck : tuple A tuple (t,c,k) containing the vector of knots, the B-spline coefficients, and the degree of the new spline. ``t(k+1) <= x <= t(n-k)``, where k is the degree of the spline. In case of a periodic spline (`per` != 0) there must be either at least k interior knots t(j) satisfying ``t(k+1)<t(j)<=x`` or at least k interior knots t(j) satisfying ``x<=t(j)<t(n-k)``. Notes ----- Based on algorithms from [1]_ and [2]_. References ---------- .. [1] W. Boehm, "Inserting new knots into b-spline curves.", Computer Aided Design, 12, p.199-201, 1980. .. [2] P. Dierckx, "Curve and surface fitting with splines, Monographs on Numerical Analysis", Oxford University Press, 1993. """ t,c,k=tck try: c[0][0] parametric = True except: parametric = False if parametric: cc = [] for c_vals in c: tt, cc_val, kk = insert(x, [t, c_vals, k], m) cc.append(cc_val) return (tt, cc, kk) else: tt, cc, ier = _fitpack._insert(per, t, c, k, x, m) if ier==10: raise ValueError,"Invalid input data" if ier: raise TypeError,"An error occurred" return (tt, cc, k)
def insert(x, tck, m=1, per=0): """ Insert knots into a B-spline. Given the knots and coefficients of a B-spline representation, create a new B-spline with a knot inserted m times at point x. This is a wrapper around the FORTRAN routine insert of FITPACK. Parameters ---------- x (u) : array_like A 1-D point at which to insert a new knot(s). If `tck` was returned from `splprep`, then the parameter values, u should be given. tck : tuple A tuple (t,c,k) returned by `splrep` or `splprep` containing the vector of knots, the B-spline coefficients, and the degree of the spline. m : int, optional The number of times to insert the given knot (its multiplicity). Default is 1. per : int, optional If non-zero, input spline is considered periodic. Returns ------- tck : tuple A tuple (t,c,k) containing the vector of knots, the B-spline coefficients, and the degree of the new spline. ``t(k+1) <= x <= t(n-k)``, where k is the degree of the spline. In case of a periodic spline (`per` != 0) there must be either at least k interior knots t(j) satisfying ``t(k+1)<t(j)<=x`` or at least k interior knots t(j) satisfying ``x<=t(j)<t(n-k)``. Notes ----- Based on algorithms from [1]_ and [2]_. References ---------- .. [1] W. Boehm, "Inserting new knots into b-spline curves.", Computer Aided Design, 12, p.199-201, 1980. .. [2] P. Dierckx, "Curve and surface fitting with splines, Monographs on Numerical Analysis", Oxford University Press, 1993. """ t, c, k = tck try: c[0][0] parametric = True except: parametric = False if parametric: cc = [] for c_vals in c: tt, cc_val, kk = insert(x, [t, c_vals, k], m) cc.append(cc_val) return (tt, cc, kk) else: tt, cc, ier = _fitpack._insert(per, t, c, k, x, m) if ier == 10: raise ValueError("Invalid input data") if ier: raise TypeError("An error occurred") return (tt, cc, k)