0

我无法动态更改点的坐标。尝试创建矢量计算但无法将坐标点设置为元素。

a = board.create('point', [1, 1], {name: 'A',color:'green',size: .5,withLabel:false}),
board.create('arrow', [[0,0], a], {color:'green'});

b = board.create('point', [-1, 1], {name: 'B',color:'red',size: .5,withLabel:false}),
board.create('arrow', [[0,0], b], {color:'red'});

let xr = a.X() + b.X();
let yr = a.Y() + b.Y();
r = board.create('point', [xr, yr], {name: 'R',color:'black',size: .5,withLabel:false}),
board.create('arrow', [[0,0], r], {color:'black'});

board.on('update', function(){
    let xr = a.X() + b.X();
    let yr = a.Y() + b.Y();
    r.point2.setPosition([xr,yr]);
    board.fullUpdate();
});

设置位置不工作。我想在每次调用更新事件时设置 xr 和 xy 的更新值。 在此处输入图像描述

4

2 回答 2

0

能够解决使用

r.point2.setPositionDirectly(JXG.COORDS_BY_USER,[xr,yr])

请注意,这仅在板更新后才有效。

board.update();

上述解决方案比使用 moveTo 更快。

于 2020-04-26T18:33:19.863 回答
0

实现您的示例的最“JSXGraphy”方式是将点的坐标定义r为函数。

var a = board.create('point', [1, 1], {
            name: 'A', color:'green', size: .5, withLabel:false
        }),
    b = board.create('point', [-1, 1], {
            name: 'B', color:'red', size: .5, withLabel:false
        }),
    r = board.create('point', [
            function() { return a.X() + b.X(); },
            function() { return a.Y() + b.Y(); }], {
            name: 'R', color:'black', size: .5, withLabel:false
        });

board.create('arrow', [[0,0], a], {color:'green'});
board.create('arrow', [[0,0], b], {color:'red'});
board.create('arrow', [[0,0], r], {color:'black'});
于 2020-04-26T20:06:09.303 回答