var brd1 = JXG.JSXGraph.initBoard('box1', {axis:true, boundingbox: [-8, 4, 8, -4]}); var s = brd1.create('slider',[[1,3],[5,3],[1,10,50]],{name:'n',snapWidth:1}); var a = brd1.create('slider',[[1,2],[5,2],[-10,-3,0]],{name:'start'}); var b = brd1.create('slider',[[1,1],[5,1],[0,2*Math.PI,10]],{name:'end'}); var f = function(x){ return Math.sin(x); }; var plot = brd1.create('functiongraph',[f,function(){return a.Value();}, function(){return b.Value();}]); var os = brd1.create('riemannsum',[f, function(){ return s.Value();}, function(){ return "left";}, function(){return a.Value();}, function(){return b.Value();} ], {fillColor:'#ffff00', fillOpacity:0.3}); brd1.create('text',[-6,-3,function(){ return 'Sum='+(JXG.Math.Numerics.riemannsum(f,s.Value(),'left',a.Value(),b.Value())).toFixed(4); }]);
var brd2 = JXG.JSXGraph.initBoard('box2', {boundingbox: [-0.02631578947368421, 1.0263157894736843, 1.2894736842105263, -0.02631578947368421]}); var level = 0; function run() { JXG.JSXGraph.freeBoard(brd2); brd2 = JXG.JSXGraph.initBoard('box2', {boundingbox: [-0.02631578947368421, 1.0263157894736843, 1.2894736842105263, -0.02631578947368421]}); level++; brd2.suspendUpdate(); paint(); brd2.unsuspendUpdate(); } function paint() { // Initial triangle var xCoords = [0, 1, 0.5]; var yCoords = [0, 0, 1]; drawPolygon(xCoords, yCoords, level); drawTriangle({x:0,y:0}, {x:1,y:0}, {x:0.5,y:1}, level); } function drawPolygon(xCoords, yCoords,level) { p1 = brd2.create('point', [xCoords[0], yCoords[0]], {visible:false,name:'',withLabel:false}); p2 = brd2.create('point', [xCoords[1], yCoords[1]], {visible:false,name:'',withLabel:false}); p3 = brd2.create('point', [xCoords[2], yCoords[2]], {visible:false,name:'',withLabel:false}); var colors=['#000000','#665566','#994499','#BB33BB','#EE99FF','#FFCCFF']; l1 = brd2.create('line',[p1,p2],{straightFirst:false,straightLast:false,strokeColor:colors[level%6],name:'',withLabel:false}); l2 = brd2.create('line',[p2,p3],{straightFirst:false,straightLast:false,strokeColor:colors[level%6],name:'',withLabel:false}); l3 = brd2.create('line',[p3,p1],{straightFirst:false,straightLast:false,strokeColor:colors[level%6],name:'',withLabel:false}); } function drawTriangle(a, b, c, level) { if (level==0) return; level -= 1; // In das übergebene Dreieck, wird ein auf dem Kopf stehendes Dreieck eingefügt var xCoords = [c.x, (c.x+b.x)/2, (a.x+c.x)/2]; var yCoords = [b.y, (c.y+a.y)/2, (c.y+a.y)/2]; drawPolygon(xCoords, yCoords,level); // 3 neue Dreiecke bestimmen a1 = a; b1 = {x:c.x, y:b.y}; c1 = {x:(a.x+c.x)/2, y:(c.y+a.y)/2}; drawTriangle(a1, b1, c1, level); a2 = {x:c.x, y:b.y}; b2 = b; c2 = {x:(c.x+b.x)/2, y:(c.y+a.y)/2}; drawTriangle(a2, b2, c2, level); a3 = {x:(a.x+c.x)/2, y:(c.y+a.y)/2}; b3 = {x:(c.x+b.x)/2, y:(c.y+a.y)/2}; c3 = c; drawTriangle(a3, b3, c3, level); } paint() ;