Cubic spline interpolation: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
Line 21: Line 21:
         p[3] = board.createElement('point', [2,1], {style:6});
         p[3] = board.createElement('point', [2,1], {style:6});


        function computeSpline() {
         var c = board.createElement('spline', p, {strokeWidth:3});
          var x = [];
          var y = [];
          for (var i=0;i<p.length;i++) {
            x[i] = p[i].X();
            y[i] = p[i].Y();
          }
          var F = JXG.Math.Numerics.splineDef(x, y);
          /*
          var px = [];
          i = 0;
          var delta = (x[x.length-1]-x[0])/board.canvasWidth*1.0;
          while(x[0] + i*delta < x[x.length-1]) {
            px[i] = x[0] + i*delta;
            i++;
          }
          var py = JXG.Math.Numerics.splineEval(px, x, y, F);
          */
          return F; // ?????
          return [px,py]; // ?????
        }         
 
         var c = board.createElement('curve', ["x",computeSpline(),"x"], {strokeWidth:3});


         function addPoint() {
         function addPoint() {

Revision as of 18:04, 7 December 2008

Under Construction -- NOT YET WORKING

Constructs a cubic spline through given points. Points can be added by clicking on "Add point".

        function addPoint() {
          p.push(board.createElement('point',[(Math.random()-0.5)*10,(Math.random()-0.5)*3],{style:6}));
          board.update();
        }