JSXGraph:使用 applyOnce() 应用线转换
JSXGraph: Applying a line transformation with applyOnce()
我正在尝试对 JSXGraph 中的线条应用一次性转换。
基于 documentation,我正在尝试像这样转换一条线:
var f = function(x) {
return x;
};
var l1 = board.create('functiongraph', [f], {
name: 'line 1',
withLabel: true,
strokeWidth: 2,
strokeColor: 'orange',
fixed: false
});
// Rotate about an intersection point with another line
var i = board.create('intersection', [l1, l2, 0], {
name: 'intersection',
fixed: true,
showInfobox: false
});
var rot = board.create(
'transform', [
function() {
// This gets the value from a slider
return s.Value();
}, i
], {
type:'rotate'
});
rot.applyOnce(l1);
board.update();
完整的来源在这里:http://maldive.ccnmtl.columbia.edu/js/ncustom.js and you can see the error I'm describing here: http://maldive.ccnmtl.columbia.edu/js/functiongraph-rotation.html
我收到错误:t[n].coords is undefined
。在我正在尝试的完整应用程序中,出现错误:TypeError: Cannot read property 'usrCoords' of undefined
所以,不管怎样,有没有人试过像这样转换一条线?
更新: 查看source后,很明显这种方法只适用于点数。所以,我不知道我的函数图是否可行。不过我这里只是用了一条直线,所以我可以用点来做点什么。
是的,applyOnce
仅针对点、文本和图像实施。另一种方法是将变换绑定到曲线。这是完整的示例(相关的只是最后一行):
var board = JXG.JSXGraph.initBoard('jxgbox', {
boundingbox: [-10, 10, 10, -10],
axis:true
});
var f = function(x) {
return x;
};
var l1 = board.create('functiongraph', [f], {
name: 'line 1', withLabel: true, fixed: false
});
var f2 = function(x) {
var alpha = 0.3;
return (1 - alpha) *
(1.4 *
1.6 ** alpha) *
(x ** -alpha);
};
var l2 = board.create('functiongraph', [f2], {
name: 'line 2', withLabel: true, fixed: false
});
// Rotate about an intersection point with another line
var intrsct = board.create('intersection', [l1, l2, 0], {
name: 'intersection', fixed: true,
});
var s = board.create(
'slider', [
[-1, -1],
[2, -1],
[0, 0, 2]
], { name:'angle'});
var rot = board.create(
'transform', [
function() {
// This gets the value from a slider
return s.Value();
}, intrsct
], { type:'rotate' });
rot.bindTo(l1);
或者,在即将发布的 0.99.7 版本中(已在夜间构建中可用),您可以创建一条新曲线,它是原始曲线的转换曲线:
var l1a = board.create('curve', [l1, rot], {
name: 'line 1a',
withLabel: true,
strokeWidth: 2,
strokeColor: 'orange',
fixed: false
});
我正在尝试对 JSXGraph 中的线条应用一次性转换。
基于 documentation,我正在尝试像这样转换一条线:
var f = function(x) {
return x;
};
var l1 = board.create('functiongraph', [f], {
name: 'line 1',
withLabel: true,
strokeWidth: 2,
strokeColor: 'orange',
fixed: false
});
// Rotate about an intersection point with another line
var i = board.create('intersection', [l1, l2, 0], {
name: 'intersection',
fixed: true,
showInfobox: false
});
var rot = board.create(
'transform', [
function() {
// This gets the value from a slider
return s.Value();
}, i
], {
type:'rotate'
});
rot.applyOnce(l1);
board.update();
完整的来源在这里:http://maldive.ccnmtl.columbia.edu/js/ncustom.js and you can see the error I'm describing here: http://maldive.ccnmtl.columbia.edu/js/functiongraph-rotation.html
我收到错误:t[n].coords is undefined
。在我正在尝试的完整应用程序中,出现错误:TypeError: Cannot read property 'usrCoords' of undefined
所以,不管怎样,有没有人试过像这样转换一条线?
更新: 查看source后,很明显这种方法只适用于点数。所以,我不知道我的函数图是否可行。不过我这里只是用了一条直线,所以我可以用点来做点什么。
是的,applyOnce
仅针对点、文本和图像实施。另一种方法是将变换绑定到曲线。这是完整的示例(相关的只是最后一行):
var board = JXG.JSXGraph.initBoard('jxgbox', {
boundingbox: [-10, 10, 10, -10],
axis:true
});
var f = function(x) {
return x;
};
var l1 = board.create('functiongraph', [f], {
name: 'line 1', withLabel: true, fixed: false
});
var f2 = function(x) {
var alpha = 0.3;
return (1 - alpha) *
(1.4 *
1.6 ** alpha) *
(x ** -alpha);
};
var l2 = board.create('functiongraph', [f2], {
name: 'line 2', withLabel: true, fixed: false
});
// Rotate about an intersection point with another line
var intrsct = board.create('intersection', [l1, l2, 0], {
name: 'intersection', fixed: true,
});
var s = board.create(
'slider', [
[-1, -1],
[2, -1],
[0, 0, 2]
], { name:'angle'});
var rot = board.create(
'transform', [
function() {
// This gets the value from a slider
return s.Value();
}, intrsct
], { type:'rotate' });
rot.bindTo(l1);
或者,在即将发布的 0.99.7 版本中(已在夜间构建中可用),您可以创建一条新曲线,它是原始曲线的转换曲线:
var l1a = board.create('curve', [l1, rot], {
name: 'line 1a',
withLabel: true,
strokeWidth: 2,
strokeColor: 'orange',
fixed: false
});