Cubic spline interpolation: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
Line 2: Line 2:
Points can be added by clicking on "Add point".
Points can be added by clicking on "Add point".
<html>
<html>
<link rel="stylesheet" type="text/css" href="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraph.css" />
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js"></script>
<form><input type="button" value="Add point" onClick="addPoint()"></form>
<form><input type="button" value="Add point" onClick="addPoint()"></form>
<div id="box" class="jxgbox" style="width:600px; height:400px;"></div>
</html>
<script language="JavaScript">
<jsxgraph width="600" height="400" box="box">
var board = JXG.JSXGraph.initBoard('box', {originX: 250, originY: 250, unitX: 50, unitY: 25, axis:true});
var board = JXG.JSXGraph.initBoard('box', {originX: 250, originY: 250, unitX: 50, unitY: 25, axis:true});
var p = [];
var p = [];
Line 24: Line 22:
}
}
            
            
</script>
</jsxgraph>
</html>


=== References ===
=== References ===

Revision as of 10:26, 25 March 2011

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();
}