Search code examples
javascriptjsxgraph

Draggable curve in JSXGraph


I want to define a curve in JSXGraph that's draggable, similar to this example:

http://jsxgraph.uni-bayreuth.de/wiki/index.php/Draggable_exponential_function

However, instead of the function's shape changing based on a single point being dragged, I want to drag the entire curve itself, without it changing shape. In fact, the mathematical properties aren't so important for this case - it doesn't matter if I don't define it as a function, I just want to have a fixed curve on the graph that I can drag.

Can anyone give me an example of how to do this?


Solution

  • A curve can be made draggable by setting the attribute fixed:false. Here is an example:

    var board = JXG.JSXGraph.initBoard('box1', {boundingbox: [-5, 20, 5, -2], axis:true});
    
    var graph = board.create('functiongraph', [
         function(x) {
            return Math.sin(x) + 5;
         }], {fixed: false});
    

    Best wishes, Alfred