Search code examples
jsxgraph

JSXGraph. Calculate displacement of point


How can i calculate displacement of a point in JSXGRAPH. Suppose there is a point A at (0, 0) location. If i drag point A from (0, 0) to (2, 0). the displacement is 2 units. My query is what is the formula in jsxgraph to calculate this displacement.


Solution

  • If you just want to calculate the distance between two JSXGraph points, say p and q, the Dist method can be used:

    p.Dist(q)
    

    If you want to determine the distance from point p to a coordinate array [x, y], it is done like this:

    JXG.Math.Geometry.distance(p.coords.usrCoords, [1, x, y]);
    

    Instead of [x, y] one has to use [1, x, y], because JSXGraph works with homogeneous coordinates, which allow to handle also infinite points.

    A dynamic example would look like this:

    var p = board.create('point', [3, 0]),
        q = board.create('point', [0, 0]),
        t = board.create('text', [1, 1, function() { return p.Dist(q); }]);