JSXGraph:使用applyOnce()

时间:2018-03-05 19:23:05

标签: javascript jsxgraph

我正在尝试将一次性转换应用于JSXGraph中的Line。

基于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,您可以在此处看到我所描述的错误:http://maldive.ccnmtl.columbia.edu/js/functiongraph-rotation.html

我收到错误:t[n].coords is undefined。在我正在尝试的完整应用程序中,我收到错误:TypeError: Cannot read property 'usrCoords' of undefined

所以,无论如何,有没有其他人试图改变这样的一条线?

更新:查看source后,显然此方法仅适用于积分。所以,我不知道我的函数图是否可行。我只是在这里使用直线,所以我可以用点做一些事情。

1 个答案:

答案 0 :(得分:0)

是的,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
});