You hit an important gap. Indeed, up to now these questions are surprsiningly hard to answer.
We will include methods to answer these questions in the next JSXGraph version.
Intersections:
Create an intersection point "i" and test if this point exists in the plane by testing if "i.Z() === 1.0"
If segments are involved, you can control with the attribute "alwaysIntersect" if the segment should be treated as line or not. However, this works not for intersections with circles. Here, segments are always treated as lines. (So far).
Incidence:
To test if a point is on an object, you have to use the complicated methods of the jsfiddle.
Here is the code of the jsfiddle:
const board = JXG.JSXGraph.initBoard('jxgbox', {
boundingbox: [-5, 5, 5, -5], axis:true
});
var circ = board.create('circle', [[-2, -2,], 1]);
var seg = board.create('segment', [[-1, -3,], [0,0]]);
var line = board.create('line', [[1, 3,], [2, -2]]);
var point = board.create('point', [-1, 1], {
attractors: [line, seg, circ],
attractorDistance: 0.2
});
var i1 = board.create('intersection', [circ, seg, 0], {
color: 'black',
name: 'i_1',
});
var i1prime = board.create('intersection', [circ, seg, 1], {
color: 'black',
name: "i_1'",
});
var i2 = board.create('intersection', [circ, line], {
color: 'black',
name: 'i_2'
});
var i3 = board.create('intersection', [seg, line], {
color: 'black',
name: 'i_3',
alwaysIntersect: false
});
// Intersections
var txt1 = board.create('text', [3, -2, function() {
return 'i_1.Z() = ' + i1.Z() + '<br>' +
'i_2.Z() = ' + i2.Z() + '<br>' +
'i_3.Z() = ' + i3.Z() + '<br>';
}]);
var txt2 = board.create('text', [-4, 3, function() {
return 'Dist(point, line) = ' + JXG.Math.Geometry.distPointLine(point.coords.usrCoords, line.stdform);
}]);
// Incidences
var txt3 = board.create('text', [-4, 2, function() {
var arr = JXG.Math.Geometry.projectCoordsToSegment(
point.coords.usrCoords,
seg.point1.coords.usrCoords,
seg.point2.coords.usrCoords
);
if (arr[1] >= 0 &&
arr[1] <= 1 &&
JXG.Math.Geometry.distance(point.coords.usrCoords, arr[0], 3) < JXG.Math.eps) {
return 'point on seg: ' + 1;
} else {
return 'point on seg: ' + 0;
}
}]);
var txt4 = board.create('text', [-4, 1, function() {
return 'point on circ = ' + (Math.abs(point.Dist(circ.center) - circ.Radius()) < JXG.Math.eps);
}]);
Best wishes,
Alfred