Arc length: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
Line 2: Line 2:
var brd = JXG.JSXGraph.initBoard('box', {axis:true, originX: 400, originY: 300, grid:true, unitX: 50, unitY: 50});
var brd = JXG.JSXGraph.initBoard('box', {axis:true, originX: 400, originY: 300, grid:true, unitX: 50, unitY: 50});
var n = brd.createElement('slider',[[1,3],[5,3],[1,10,50]],{name:'n'});
var n = brd.createElement('slider',[[1,3],[5,3],[1,10,50]],{name:'n'});
var f = function(x){ return 0.2*x*x+0.5*Math.sin(x); }
var f = function(x){ return 0.2*x*x+2.0*Math.sin(x); }
var plot = brd.createElement('functiongraph',[f]);
var plot = brd.createElement('functiongraph',[f]);
 
var start -1.0;
var end = 5.0;
var sc = brd.createElement('curve',[[0],[0]]);
var sc = brd.createElement('curve',[[0],[0]]);
sc.updateDataArray = function() {
sc.updateDataArray = function() {
Line 10: Line 11:
   var m = n.Value();
   var m = n.Value();
   m = Math.floor(m);
   m = Math.floor(m);
   var d = (5-0)/m;
   var d = (end-start)/m;
   this.dataX = [];
   this.dataX = [];
   this.dataY = [];
   this.dataY = [];
   this.dataX[0] = 0.0;   
   this.dataX[0] = start;   
   this.dataY[0] = f(0.0);   
   this.dataY[0] = f(start);   
   for (i=1;i<=m;i++) {
   for (i=1;i<=m;i++) {
     this.dataX.push(0.0+i*d);   
     this.dataX.push(start+i*d);   
     this.dataY.push(f(0.0+(i-1)*d));   
     this.dataY.push(f(start+(i-1)*d));   
     this.dataX.push(0.0+i*d);   
     this.dataX.push(start+i*d);   
     this.dataY.push(f(0.0+i*d));   
     this.dataY.push(f(start+i*d));   
   }   
   }   
}
}
Line 27: Line 28:
   var m = n.Value();
   var m = n.Value();
   m = Math.floor(m);
   m = Math.floor(m);
   var d = (5-0)/m;
   var d = (end-start)/m;
   this.dataX = [];
   this.dataX = [];
   this.dataY = [];
   this.dataY = [];
   this.dataX[0] = 0.0;   
   this.dataX[0] = start;   
   this.dataY[0] = f(0.0);   
   this.dataY[0] = f(start);   
   for (i=1;i<=m;i++) {
   for (i=1;i<=m;i++) {
     this.dataX.push(0.0+i*d);   
     this.dataX.push(start+i*d);   
     this.dataY.push(f(0.0+i*d));   
     this.dataY.push(f(start+i*d));   
   }   
   }   
}
}

Revision as of 15:31, 11 June 2009

The underlying JavaScript code