Difference between revisions of "Cubic spline interpolation"
From JSXGraph Wiki
Jump to navigationJump to searchA WASSERMANN (talk | contribs) |
|||
(3 intermediate revisions by 2 users not shown) | |||
Line 2: | Line 2: | ||
Points can be added by clicking on "Add point". | Points can be added by clicking on "Add point". | ||
<html> | <html> | ||
− | |||
− | |||
<form><input type="button" value="Add point" onClick="addPoint()"></form> | <form><input type="button" value="Add point" onClick="addPoint()"></form> | ||
− | < | + | </html> |
− | + | <jsxgraph width="600" height="400" box="box"> | |
− | var board = JXG.JSXGraph.initBoard('box', { | + | var board = JXG.JSXGraph.initBoard('box', {boundingbox: [-5, 10, 7, -5], axis:true}); |
var p = []; | var p = []; | ||
− | p[0] = board.create('point', [-1,2], { | + | p[0] = board.create('point', [-1,2], {size: 4, face: 'o'}); |
− | p[1] = board.create('point', [0,-1], { | + | p[1] = board.create('point', [0,-1], {size: 4, face: 'o'}); |
− | p[2] = board.create('point', [1,0], { | + | p[2] = board.create('point', [1,0], {size: 4, face: 'o'}); |
− | p[3] = board.create('point', [2,1], { | + | p[3] = board.create('point', [2,1], {size: 4, face: 'o'}); |
var c = board.create('spline', p, {strokeWidth:3}); | var c = board.create('spline', p, {strokeWidth:3}); | ||
Line 20: | Line 18: | ||
function addPoint() { | function addPoint() { | ||
− | p.push(board.create('point',[(Math.random()-0.5)*10,(Math.random()-0.5)*3],{ | + | p.push(board.create('point',[(Math.random()-0.5)*10,(Math.random()-0.5)*3],{size: 4, face: 'o'})); |
board.update(); | board.update(); | ||
− | } | + | } |
− | + | </jsxgraph> | |
− | |||
− | </ | ||
=== References === | === References === | ||
Line 32: | Line 28: | ||
=== The underlying JavaScript code === | === The underlying JavaScript code === | ||
<source lang="javascript"> | <source lang="javascript"> | ||
− | var board = JXG.JSXGraph.initBoard('box', { | + | var board = JXG.JSXGraph.initBoard('box', {boundingbox: [-5, 10, 7, -5], axis:true}); |
var p = []; | var p = []; | ||
− | p[0] = board.create('point', [-1,2], { | + | p[0] = board.create('point', [-1,2], {size: 4, face: 'o'}); |
− | p[1] = board.create('point', [0,-1], { | + | p[1] = board.create('point', [0,-1], {size: 4, face: 'o'}); |
− | p[2] = board.create('point', [1,0], { | + | p[2] = board.create('point', [1,0], {size: 4, face: 'o'}); |
− | p[3] = board.create('point', [2,1], { | + | p[3] = board.create('point', [2,1], {size: 4, face: 'o'}); |
var c = board.create('spline', p, {strokeWidth:3}); | var c = board.create('spline', p, {strokeWidth:3}); | ||
Line 45: | Line 41: | ||
function addPoint() { | function addPoint() { | ||
− | p.push(board.create('point',[(Math.random()-0.5)*10,(Math.random()-0.5)*3],{ | + | p.push(board.create('point',[(Math.random()-0.5)*10,(Math.random()-0.5)*3],{size: 4, face: 'o'})); |
board.update(); | board.update(); | ||
− | } | + | }</source> |
− | </source> | ||
[[Category:Examples]] | [[Category:Examples]] | ||
+ | [[Category:Interpolation]] |
Latest revision as of 15:09, 7 June 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', {boundingbox: [-5, 10, 7, -5], axis:true});
var p = [];
p[0] = board.create('point', [-1,2], {size: 4, face: 'o'});
p[1] = board.create('point', [0,-1], {size: 4, face: 'o'});
p[2] = board.create('point', [1,0], {size: 4, face: 'o'});
p[3] = board.create('point', [2,1], {size: 4, face: 'o'});
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],{size: 4, face: 'o'}));
board.update();
}