Point 'fixed' in one direction: Difference between revisions
From JSXGraph Wiki
A WASSERMANN (talk | contribs) (Created page with "<jsxgraph width="600" height="600"> var brd = JXG.JSXGraph.initBoard('jxgbox',{axis:false,boundingbox:[-2,2,2,-2],keepaspectratio:true}); var A = brd.create('point', [1,0]); var...") |
A WASSERMANN (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
`A` and `B` are free points. Whenever the board is updated, e.g. | |||
after a drag event, the x-coordinate of `A` is set to 1 and | |||
the y-coordinate of `B` is set to 1. Therefore, `A` moves | |||
on a vertical line, `B` moves on a horizontal line. | |||
<jsxgraph width="600" height="600"> | <jsxgraph width="600" height="600"> | ||
var brd = JXG.JSXGraph.initBoard('jxgbox',{axis: | var brd = JXG.JSXGraph.initBoard('jxgbox',{axis:true,boundingbox:[-1,2,2,-1]}); | ||
var A = brd.create('point', [1,0]); | var A = brd.create('point', [1,0]); | ||
Line 11: | Line 15: | ||
</jsxgraph> | </jsxgraph> | ||
===The JavaScript code=== | |||
<source lang="javascript"> | |||
var brd = JXG.JSXGraph.initBoard('jxgbox',{axis:true,boundingbox:[-1,2,2,-1]}); | |||
var A = brd.create('point', [1,0]); | |||
var B = brd.create('point', [0,1]); | |||
brd.on('update', function(){ | |||
A.moveTo([1, A.Y()]); | |||
B.moveTo([B.X(), 1]); | |||
}); | |||
</source> | |||
[[Category:Examples]] |
Revision as of 13:08, 8 October 2012
`A` and `B` are free points. Whenever the board is updated, e.g. after a drag event, the x-coordinate of `A` is set to 1 and the y-coordinate of `B` is set to 1. Therefore, `A` moves on a vertical line, `B` moves on a horizontal line.
The JavaScript code
var brd = JXG.JSXGraph.initBoard('jxgbox',{axis:true,boundingbox:[-1,2,2,-1]});
var A = brd.create('point', [1,0]);
var B = brd.create('point', [0,1]);
brd.on('update', function(){
A.moveTo([1, A.Y()]);
B.moveTo([B.X(), 1]);
});