Need glider to move with point!

459 views
Skip to first unread message

solo...@gmail.com

unread,
Sep 11, 2012, 10:54:32 AM9/11/12
to jsxg...@googlegroups.com
Hello, I need help figuring out how to move the glider point based on the Point A X position..

The code I have is:

var board = JXG.JSXGraph.initBoard('box', 
{
boundingbox: [0, 1000, .3, -30], //change bounding box [left, top, right, bottom]
axis:true,
});
var p = [];

var p1 = board.create('point', [-1.0, 0.0], {fixed: true});
var p2 = board.create('point', [0.4, 0.0], {fixed: true});
var l1 = board.create('line', [p1, p2], {fixed: true, highlight: false, strokeColor: '#000000'});



var glider = board.create('glider', [0, 0, l1], {snapToGrid: true, snapSizeX: .01, snapSizeY: .01, name: 'glider'});

var p3 = board.create('point', [.1, 250.0], {snapToGrid: true, snapSizeX: .01, snapSizeY: 10, name: 'Point A'});

var l2 = board.create('line', [glider, p3]);
var perp1 = board.create('perpendicular', [l1, p3], {highlight: false});


//////////////
so what I need is that when I move Point A either to the left or right... I need the glider to move the same amount.

thank you for your help.

M

Joe Simons

unread,
Sep 11, 2012, 3:54:03 PM9/11/12
to jsxg...@googlegroups.com, solo...@gmail.com
One way to do this is by using the drag event handler.
See this example:
in which the y coordinate of glider 'a' depends on glider 'b'

Michael

unread,
Sep 12, 2012, 7:55:25 AM9/12/12
to jsxg...@googlegroups.com
On Tue, Sep 11, 2012 at 9:54 PM, Joe Simons <mrjoe...@gmail.com> wrote:
One way to do this is by using the drag event handler.
See this example:
in which the y coordinate of glider 'a' depends on glider 'b'
That's  an excellent solution if you want to be able to move the glider. If the glider should be fixed, the perpendicular point element (an orthogonal projection of a point onto a line) would be easier to use.

solo...@gmail.com

unread,
Sep 12, 2012, 12:56:41 PM9/12/12
to jsxg...@googlegroups.com
Thank you Joe and Michael,

Your suggestion looks good.

But before you replied, i had achieved what I needed using the code below. Thanks for the help tho.

And lots of Thanks to the JSXGraph team, for developing such a wonderful piece of software!

var board = JXG.JSXGraph.initBoard('box', 
{
boundingbox: [0, 700, .3, -20],
grid: false,
axis: false,
keepaspectratio: false,
});

var p = [];

// Line1 in the X coordinate
var p1 = board.create('point', [-1.0, 0.0], {fixed: true});
var p2 = board.create('point', [0.4, 0.0], {fixed: true});
var l1 = board.create('line', [p1, p2], {fixed: true, highlight: false, strokeColor: '#000000'});

// Point B...glider that glides on Line1
var glider = board.create('glider', [0, 0, l1], {name: 'Point B', snapToGrid: true, snapSizeX: .001});

//Point A, used to control slope of Line 2
var p4 = board.create('point', [.2, 250], {name: 'Point A'});

//Line 2, connects point A and B
var l2 = board.create('line', [glider, p4]);

//This translates Point C, depends on Point A
translateTrans = board.create('transform',[0.1,0],  {type:'translate'});

//Point C, used to move the perpendicular line
var p3 = board.create('point', [glider, translateTrans], {visible: true});


//Creates a perpendicular to Line1
var perp1 = board.create('perpendicular', [l1, p3], {highlight: false, strokeWidth: 1});

//Creates the Intersection point X
var inter = board.create('intersection',[perp1,l2,0],{face: 'x', name: '', size: 8});
Reply all
Reply to author
Forward
0 new messages