如何在等式图中设置 JSXGraph 中可拖动点的初始位置?
How to set initial position of draggable points in JSXGraph in an equation graph?
我正在开发一个网络软件,它在 JSXGraph 上绘制一个带有 2 个变量的交互式多项式方程,我需要方程的导数为 0 的每个点都有一个可拖动点,并且当我拖动一个点时, 只有曲线拖动点之后 1 点和之前 1 点之间的间隔有人知道我该怎么做吗?
抱歉耽搁了。我猜,你需要的是Hermite插值。我最近在 Google 组 (https://groups.google.com/forum/#!topic/jsxgraph/OHls2NTOmUA) 中举了一个例子。 JSXGraph 中还没有集成 Hermite 插值,不过好像有需求,可以考虑下。
代码如下:
JXG.Math.Numerics.hermitePolynomial = function (p, derivatives) {
var w = [],
Lii = [],
/** @ignore */
fct = function (x, suspendedUpdate) {
var i, k, xi, s,
L, Hi, Hi_hat,
len = p.length,
num = 0,
denom = 0;
if (!suspendedUpdate) {
// Compute denominator
for (i = 0; i < len; i++) {
w[i] = 1.0;
Lii[i] = 0.0;
xi = p[i].X();
for (k = 0; k < len; k++) {
if (k !== i) {
w[i] *= (xi - p[k].X());
Lii[i] += 1 / (xi - p[k].X());
}
}
w[i] = 1 / w[i];
}
}
s = 0.0;
for (i = 0; i < len; i++) {
xi = p[i].X();
L = w[i];
for (k = 0; k < len; k++) {
if (k !== i) {
L *= (x - p[k].X());
}
}
Hi = (1.0 - 2 * (x - xi) * Lii[i]) * L * L;
Hi_hat = (x -xi) * L * L;
s += p[i].Y() * Hi + derivatives[i] * Hi_hat;
}
return s;
};
return fct;
};
var board = JXG.JSXGraph.initBoard("jxgbox", {
boundingbox: [-5, 6, 6, -5],
axis: true
});
var p = [];
// Define the points
p[0] = board.create('point', [-1,2], {size:4});
p[1] = board.create('point', [1,-2], {size:4});
p[2] = board.create('point', [3,-1], {size:4});
// The derivates at this points are all zero.
var derivatives = [0, 0, 0];
var f = JXG.Math.Numerics.hermitePolynomial(p, derivatives);
var graph = board.create('functiongraph', [f, -10, 10], {strokeWidth:2});
现场演示在 https://jsfiddle.net/vcL7aepo/278/
最良好的祝愿,
阿尔弗雷德
我正在开发一个网络软件,它在 JSXGraph 上绘制一个带有 2 个变量的交互式多项式方程,我需要方程的导数为 0 的每个点都有一个可拖动点,并且当我拖动一个点时, 只有曲线拖动点之后 1 点和之前 1 点之间的间隔有人知道我该怎么做吗?
抱歉耽搁了。我猜,你需要的是Hermite插值。我最近在 Google 组 (https://groups.google.com/forum/#!topic/jsxgraph/OHls2NTOmUA) 中举了一个例子。 JSXGraph 中还没有集成 Hermite 插值,不过好像有需求,可以考虑下。
代码如下:
JXG.Math.Numerics.hermitePolynomial = function (p, derivatives) {
var w = [],
Lii = [],
/** @ignore */
fct = function (x, suspendedUpdate) {
var i, k, xi, s,
L, Hi, Hi_hat,
len = p.length,
num = 0,
denom = 0;
if (!suspendedUpdate) {
// Compute denominator
for (i = 0; i < len; i++) {
w[i] = 1.0;
Lii[i] = 0.0;
xi = p[i].X();
for (k = 0; k < len; k++) {
if (k !== i) {
w[i] *= (xi - p[k].X());
Lii[i] += 1 / (xi - p[k].X());
}
}
w[i] = 1 / w[i];
}
}
s = 0.0;
for (i = 0; i < len; i++) {
xi = p[i].X();
L = w[i];
for (k = 0; k < len; k++) {
if (k !== i) {
L *= (x - p[k].X());
}
}
Hi = (1.0 - 2 * (x - xi) * Lii[i]) * L * L;
Hi_hat = (x -xi) * L * L;
s += p[i].Y() * Hi + derivatives[i] * Hi_hat;
}
return s;
};
return fct;
};
var board = JXG.JSXGraph.initBoard("jxgbox", {
boundingbox: [-5, 6, 6, -5],
axis: true
});
var p = [];
// Define the points
p[0] = board.create('point', [-1,2], {size:4});
p[1] = board.create('point', [1,-2], {size:4});
p[2] = board.create('point', [3,-1], {size:4});
// The derivates at this points are all zero.
var derivatives = [0, 0, 0];
var f = JXG.Math.Numerics.hermitePolynomial(p, derivatives);
var graph = board.create('functiongraph', [f, -10, 10], {strokeWidth:2});
现场演示在 https://jsfiddle.net/vcL7aepo/278/
最良好的祝愿, 阿尔弗雷德