home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l455 / 5.ddi / SPLINES.DI$ / SPCRV.M < prev    next >
Encoding:
Text File  |  1993-03-11  |  1.4 KB  |  53 lines

  1. function curve=spcrv(x,k,maxpnt)
  2. % SPCRV    Generate a spline curve.
  3. %
  4. %     [curve=] spcrv(x[,k,maxpnt])
  5. %
  6. %  uses repeated midpoint knot insertion to generate the curve
  7. %         
  8. %     t /-->  sum  B(t-k/2;j,...,j+k)*x(j) ,
  9. %              j          
  10. %
  11. %  from the input (d,n)-array  x  ,  with  d=1 or 2 . 
  12. %  The insertion process stops as soon as there are >= maxpnt knots.
  13.  
  14. % C. de Boor / latest change: Feb.25, 1989
  15. % Copyright (c) 1990-92 by Carl de Boor and The MathWorks, Inc.
  16.  
  17.  
  18. y=x;kntstp=1;
  19. if (nargin<2), k=4;end
  20. [d,n]=size(x);
  21. if (n<k),
  22.    fprintf('The number of points, %.0f, should be at least as\n',n)
  23.    fprintf('big as the given order, k = %.0f.\n',k)
  24.    error('')
  25. elseif (k<2),
  26.    fprintf('The order, k = %.0f, should be at least 2.\n',k)
  27.    error('')
  28. else
  29.    if (k>2);
  30.       if (nargin<3);maxpnt=100;end
  31.       while (n<maxpnt);
  32.          kntstp=2*kntstp;m=2*n;yy(:,2:2:m)=y;yy(:,1:2:m)=y;
  33.          for r=2:k;
  34.             yy(:,2:m)=(yy(:,2:m)+yy(:,1:m-1))*.5;
  35.          end
  36.          y=yy(:,k:m);n=length(y);
  37.       end
  38.    end
  39.  
  40.    if (nargout==1);curve=y;end
  41.  
  42.    %  disable the plotting of breakpoints for the time being
  43.  
  44. %  kl=floor((k-2)*.5);knots=1:kntstp:n;
  45. %  yk=.5*(y(:,knots+kl)+y(:,knots+k-2-kl));
  46. %  if (d==1);
  47. %     plot([1:n],y,symbol,knots,yk,'x');
  48. %  else
  49. %     plot(y(1,:),y(2,:),symbol,yk(1,:),yk(2,:),'x');
  50. %  end
  51.  
  52. end
  53.