如何使抛物线从给定的点变化计算,随着点的移动而变化?
我试图让学生能够拖动三分,以显示二次截距的三个拦截(带有真正的根源),然后让jsxgraph绘制与这三分相匹配的抛物线。我的数学效果没有戏剧性,但是我无法说服它随着要点的移动而进行更新。
这是 fiddle 我一直在努力。
当我使用.ON拖动点('drag'方法,但我无法弄清楚如何清除以前的图(似乎我也不必使用该方法,我也无法弄清楚如何使用该方法? )。
const board = JXG.JSXGraph.initBoard('jxgbox', {
boundingbox: [-5, 5, 5, -5],
axis: true
});
var xi1 = board.create('point', [2, 1], {
visible: true,
snapToGrid: true,
snapSizeX: 0.1,
snapSizeY: 0.1
});
var xi2 = board.create('point', [-2, 1], {
visible: true,
snapToGrid: true,
snapSizeX: 0.1,
snapSizeY: 0.1
});
var el0 = board.create('line', [
[0, 0],
[0, 1]
], {
strokeOpacity: .2,
strokeColor: '#000000',
fixed: true,
name: 'x=0'
});
var yi = board.create('glider', [0, 1, el0], {
name: 'Y-Intercept',
visible: true,
snapToGrid: true,
snapSizeX: 0.1,
snapSizeY: 0.1
});
yi.on('drag', function() {
board.removeObject(f);
var p = parseFloat(xi1.X());
var q = parseFloat(xi2.X());
var r = parseFloat(yi.Y());
var a = r / (p * q);
var b = (r * (q + p)) / (p * q);
var c = r;
var func = a.toString() + '*x^2+' + b.toString() + '*x+' + c.toString();
var f = board.jc.snippet(func, true, 'x', true);
var graph = board.create('functiongraph', [f, -10, 10], {
strokeColor: '#003399',
strokeWidth: 2
});
var txt1 = board.create('text', [3, 4, function() {
return "The current equation is:" + func;
}]);
});
I'm trying to get students to be able to drag the three points around to show the three intercepts of a quadratic (with real roots) then have jsxgraph draw the parabola that matches those three points. I've got the maths working no dramas but I can't convince it to update as the points move.
Here's the fiddle I've been working on.
I can get the graph to re-plot when I drag the points using the .on('drag' method but I can't work out how to clear previous plots (also is seems like I shouldn't have to use that method?).
const board = JXG.JSXGraph.initBoard('jxgbox', {
boundingbox: [-5, 5, 5, -5],
axis: true
});
var xi1 = board.create('point', [2, 1], {
visible: true,
snapToGrid: true,
snapSizeX: 0.1,
snapSizeY: 0.1
});
var xi2 = board.create('point', [-2, 1], {
visible: true,
snapToGrid: true,
snapSizeX: 0.1,
snapSizeY: 0.1
});
var el0 = board.create('line', [
[0, 0],
[0, 1]
], {
strokeOpacity: .2,
strokeColor: '#000000',
fixed: true,
name: 'x=0'
});
var yi = board.create('glider', [0, 1, el0], {
name: 'Y-Intercept',
visible: true,
snapToGrid: true,
snapSizeX: 0.1,
snapSizeY: 0.1
});
yi.on('drag', function() {
board.removeObject(f);
var p = parseFloat(xi1.X());
var q = parseFloat(xi2.X());
var r = parseFloat(yi.Y());
var a = r / (p * q);
var b = (r * (q + p)) / (p * q);
var c = r;
var func = a.toString() + '*x^2+' + b.toString() + '*x+' + c.toString();
var f = board.jc.snippet(func, true, 'x', true);
var graph = board.create('functiongraph', [f, -10, 10], {
strokeColor: '#003399',
strokeWidth: 2
});
var txt1 = board.create('text', [3, 4, function() {
return "The current equation is:" + func;
}]);
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果同事向我展示了一种在不使用JC.Snippet方法的情况下绘制功能的另一种方法。 这是小提琴。
基本上是AddCurve做我想要的。
Had a colleague show me an alternative way of getting the function to draw without using the jc.snippet method. Here's the fiddle.
Basically addcurve does what I want.