Difference between revisions of "Cubic spline interpolation"

From JSXGraph Wiki
Jump to navigationJump to search
Line 7: Line 7:
 
<div id="box" class="jxgbox" style="width:600px; height:400px;"></div>
 
<div id="box" class="jxgbox" style="width:600px; height:400px;"></div>
 
<script language="JavaScript">
 
<script language="JavaScript">
        board = JXG.JSXGraph.initBoard('box', {originX: 250, originY: 250, unitX: 50, unitY: 25});
+
var board = JXG.JSXGraph.initBoard('box', {originX: 250, originY: 250, unitX: 50, unitY: 25, axis:true});
        // Axes
+
var p = [];
        b1axisx = board.createElement('axis', [[0,0], [1,0]], {});
+
p[0] = board.create('point', [-1,2], {style:6});
        b1axisy = board.createElement('axis', [[0,0], [0,1]], {});
+
p[1] = board.create('point', [0,-1], {style:6});
 +
p[2] = board.create('point', [1,0], {style:6});
 +
p[3] = board.create('point', [2,1], {style:6});
  
        var p = [];
+
var c = board.create('spline', p, {strokeWidth:3});
        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});
+
var g = board.create('glider', [1.5,0,c], {name:'',style:8});
 
+
var t = board.create('tangent', [g], {dash:2,strokeColor:'#aa0000'});
        var g = board.createElement('glider', [1.5,0,c], {name:'',style:8});
 
        var t = board.createElement('tangent', [g], {dash:2,strokeColor:'#aa0000'});
 
 
      
 
      
        function addPoint() {
+
function addPoint() {
          p.push(board.createElement('point',[(Math.random()-0.5)*10,(Math.random()-0.5)*3],{style:6}));
+
    p.push(board.create('point',[(Math.random()-0.5)*10,(Math.random()-0.5)*3],{style:6}));
          board.update();
+
    board.update();
        }
+
}
 
            
 
            
 
</script>
 
</script>
Line 36: Line 32:
 
=== 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});
+
var board = JXG.JSXGraph.initBoard('box', {originX: 250, originY: 250, unitX: 50, unitY: 25, axis:true});
        // Axes
+
var p = [];
        b1axisx = board.createElement('axis', [[0,0], [1,0]], {});
+
p[0] = board.create('point', [-1,2], {style:6});
        b1axisy = board.createElement('axis', [[0,0], [0,1]], {});
+
p[1] = board.create('point', [0,-1], {style:6});
 +
p[2] = board.create('point', [1,0], {style:6});
 +
p[3] = board.create('point', [2,1], {style:6});
  
        var p = [];
+
var c = board.create('spline', p, {strokeWidth:3});
        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});
 
 
 
        var g = board.createElement('glider', [1.5,0,c], {name:'',style:8});
 
        var t = board.createElement('tangent', [g], {dash:2,strokeColor:'#aa0000'});
 
 
 
        function addPoint() {
 
          p.push(board.createElement('point',[(Math.random()-0.5)*10,(Math.random()-0.5)*3],{style:6}));
 
          board.update();
 
        }
 
  
 +
var g = board.create('glider', [1.5,0,c], {name:'',style:8});
 +
var t = board.create('tangent', [g], {dash:2,strokeColor:'#aa0000'});
 +
   
 +
function addPoint() {
 +
    p.push(board.create('point',[(Math.random()-0.5)*10,(Math.random()-0.5)*3],{style:6}));
 +
    board.update();
 +
}
 
</source>
 
</source>
  
  
 
[[Category:Examples]]
 
[[Category:Examples]]

Revision as of 15:18, 1 February 2010

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

References

The underlying JavaScript code

var board = JXG.JSXGraph.initBoard('box', {originX: 250, originY: 250, unitX: 50, unitY: 25, axis:true});
var p = [];
p[0] = board.create('point', [-1,2], {style:6});
p[1] = board.create('point', [0,-1], {style:6});
p[2] = board.create('point', [1,0], {style:6});
p[3] = board.create('point', [2,1], {style:6});

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

var g = board.create('glider', [1.5,0,c], {name:'',style:8});
var t = board.create('tangent', [g], {dash:2,strokeColor:'#aa0000'});
     
function addPoint() {
    p.push(board.create('point',[(Math.random()-0.5)*10,(Math.random()-0.5)*3],{style:6}));
    board.update();
}