intersection exist ?

23 views
Skip to first unread message

jean Mj

unread,
May 21, 2021, 11:04:51 AM5/21/21
to JSXGraph
Hello, how can I know if the intersection between a circle and a line exists?
And what about a circle and a segment? Do we have the information if the point is on the segment?

Alfred Wassermann

unread,
May 28, 2021, 5:24:32 AM5/28/21
to JSXGraph
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.
I set up a jsfiddle (https://jsfiddle.net/bnedm095/3/) which shows how to get information about intersections and incidence up to now:

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



Alfred Wassermann

unread,
May 28, 2021, 7:06:52 AM5/28/21
to JSXGraph
OK; a first version of point.isOn(element) has been implemented and will be available on today's nightly build.
Best wishes,
Alfred

Reply all
Reply to author
Forward
0 new messages