esoteric elf
esoteric elf

Reputation: 55

Jsxgraph dependent point

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

This is a simple demonstration of quadratic function. I would like the vertex change its position accordingly with the slider a, b or c. But it didn't work out.

I am not even close to an apprentice of javascript. Please advise, pretty much appreciate.

Upvotes: 0

Views: 229

Answers (2)

Alfred Wassermann
Alfred Wassermann

Reputation: 2323

Another (simpler) solution would be to make the coordinates of the point d dynamic, i.e. supply functions instead of fixed coordinates:

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

Upvotes: 0

esoteric elf
esoteric elf

Reputation: 55

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

though i am not sure i fully understand how, i tried to solve and it's done

Upvotes: 0

Related Questions