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())]);

这是二次函数的简单演示。我希望顶点使用滑块 a、b 或 c 相应地更改其位置。但它没有成功。

我什至没有接近 javascript 的学徒。请指教,非常感谢。

4

2 回答 2

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();
 });

虽然我不确定我是否完全理解如何,但我尝试解决并完成了

于 2016-06-14T01:39:23.457 回答
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());
            }]);
于 2016-06-14T07:15:49.083 回答