Cubic spline interpolation: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
Line 34: Line 34:
=== The underlying JavaScript code ===
=== The underlying JavaScript code ===
<source lang="javascript">
<source lang="javascript">
        board = JXG.JSXGraph.initBoard('box', {originX: 250, originY: 250, unitX: 50, unitY: 25});
        // Axes
        b1axisx = board.createElement('axis', [[0,0], [1,0]], {});
        b1axisy = board.createElement('axis', [[0,0], [0,1]], {});
        var p = [];
        p[0] = board.createElement('point', [-1,2], {style:6});
        p[1] = board.createElement('point', [0,-1], {style:6});
        p[2] = board.createElement('point', [1,0], {style:6});
        p[3] = board.createElement('point', [2,1], {style:6});
        var c = board.createElement('spline', p, {strokeWidth:3});
         function addPoint() {
         function addPoint() {
           p.push(board.createElement('point',[(Math.random()-0.5)*10,(Math.random()-0.5)*3],{style:6}));
           p.push(board.createElement('point',[(Math.random()-0.5)*10,(Math.random()-0.5)*3],{style:6}));

Revision as of 11:11, 30 March 2009

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

References

The underlying JavaScript code

        board = JXG.JSXGraph.initBoard('box', {originX: 250, originY: 250, unitX: 50, unitY: 25});
        // Axes
        b1axisx = board.createElement('axis', [[0,0], [1,0]], {});
        b1axisy = board.createElement('axis', [[0,0], [0,1]], {});

        var p = [];
        p[0] = board.createElement('point', [-1,2], {style:6});
        p[1] = board.createElement('point', [0,-1], {style:6});
        p[2] = board.createElement('point', [1,0], {style:6});
        p[3] = board.createElement('point', [2,1], {style:6});

        var c = board.createElement('spline', p, {strokeWidth:3});

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