Alfred Wassermann
unread,Jul 5, 2013, 3:57:08 AM7/5/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to jsxg...@googlegroups.com
Not quite, because hasPoint() wants screen coordinates as input parameters.
Therefore, you should define a method "point.isOn(line)" like this:
JXG.Point.prototype.isOn = function(line) {
return line.hasPoint(this.coords.scrCoords[1], this.coords.scrCoords[2]);
};
But beware, the hasPoint-methods of JSXGraph use some sensitive are around the line which is optimized for
mouse and touch devices, i.e. hasPoint() gives not a mathematically correct result.
If you want to have an exact result (up to some numerical instability) you should use
the following method:
JXG.Point.prototype.isOnExact = function(line) {
var r = JXG.Math.innerProduct(this.coords.usrCoords, line.stdform, 3);
return (Math.abs(r) < JXG.Math.eps);
};
Now, it can be used like this:
var board = JXG.JSXGraph.initBoard('box', {boundingbox: [-10, 10, 10, -10]});
var A = ...
var B = ...
var line = board.create('line', [A, B]);
var po = board.create('point', [-7, 2]);
board.on('update', function() {
document.getElementById('out').innerHTML = po.isOnExact(line);
});
Best wishes,
Alfred