Share JSXGraph: example "Cubic spline interpolation"

JSXGraph
Share JSXGraph: example "Cubic spline interpolation"
This website is a beta version. The official release will be in **2023**.

Cubic spline interpolation

Have also a look at "B-splines"or "Catmull-Rom splines".
A cubic spline function graph through given points is constructed. Points can be added by clicking on "Add point".
<input type="button" value="Add point" onClick="addPoint()">
// Define the id of your board in BOARDID

const board = JXG.JSXGraph.initBoard(BOARDID, {boundingbox: [-5, 10, 7, -5], axis:true});

// Create 4 initial points
var p = [];
p[0] = board.create('point', [-1,2], {size: 4});
p[1] = board.create('point', [0,-1], {size: 4});
p[2] = board.create('point', [1,0], {size: 4});
p[3] = board.create('point', [2,1], {size: 4});

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

// Add tangent
var g = board.create('glider', [1.5, 0, c], {name:'', face:'<>', color: 'blue'});
var t = board.create('tangent', [g], {dash:2, strokeColor:'#aa0000'});
     
var addPoint = function() {
    p.push(board.create('point', [(Math.random() - 0.5) * 10, (Math.random() - 0.5) * 3], {size: 4}));
    board.update();
    board.update();
}