2016-06-13 88 views
0

var brd = JXG.JSXGraph.initBoard('box', {boundingbox: [-10, 10, 10, -10], axis:true, showcopyright:false}), a = brd.create('slider',[[2,-5],[7,-5],[-5,1,5]], {name:'a'}), b = brd.create('slider',[[2,-6],[7,-6],[-5,0,5]], {name:'b'}), c = brd.create('slider',[[2,-7],[7,-7],[-5,0,5]], {name:'c'}), f = brd.create('functiongraph',[function(x){ return a.Value()*x*x + b.Value()*x + c.Value(); }]); var d = brd.create('point',[(4*a.Value()*c.Value()-b.Value()*b.Value())/(4*a.Value()),-1*b.Value()/(2*a.Value())]);Jsxgraph依賴點

這是一個二次函數的簡單演示。我希望頂點通過滑塊a,b或c相應地改變它的位置。但它沒有解決。

我甚至沒有接近JavaScript的學徒。請指教,非常感謝。

回答

0
var brd = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [-10, 10, 10, -10], axis:true, showcopyright:false}), 
a = brd.create('slider',[[2,-5],[7,-5],[-5,1,5]], {name:'a'}), 
b = brd.create('slider',[[2,-6],[7,-6],[-5,3,5]], {name:'b'}), 
c = brd.create('slider',[[2,-7],[7,-7],[-5,4,5]], {name:'c'}), 
f = brd.create('functiongraph',[function(x){ 
     return a.Value()*x*x + b.Value()*x + c.Value(); 
    }]); d = brd.create('point',[-1*b.Value()/(2*a.Value()),(4*a.Value()*c.Value()-b.Value()*b.Value())/(4*a.Value())],{fixed:true}); 
brd.on('move', function() {brd.suspendUpdate(); 
brd.removeObject(d); 
d = brd.create('point',[-1*b.Value()/(2*a.Value()),(4*a.Value()*c.Value()-b.Value()*b.Value())/(4*a.Value())],{fixed:true}); 
    brd.unsuspendUpdate(); 
}); 

,雖然我不知道我完全明白怎麼回事,我試圖解決它完成

0

另一個(簡單的)解決方案將是使該點的座標,而不是d動態的,即供給函數固定座標:

var brd = JXG.JSXGraph.initBoard('box', 
     {boundingbox: [-10, 10, 10, -10], axis:true, showcopyright:false}), 
    a = brd.create('slider',[[2,-5],[7,-5],[-5,1,5]], {name:'a'}), 
    b = brd.create('slider',[[2,-6],[7,-6],[-5,0,5]], {name:'b'}), 
    c = brd.create('slider',[[2,-7],[7,-7],[-5,0,5]], {name:'c'}), 
    f = brd.create('functiongraph',[ 
      function(x){ 
       return a.Value()*x*x + b.Value()*x + c.Value(); 
      }]), 
    d = brd.create('point',[ 
      function() { 
       return (4*a.Value()*c.Value()-b.Value()*b.Value())/(4*a.Value()); 
      }, 
      function() { 
       return -1*b.Value()/(2*a.Value()); 
      }]);