Search code examples
javascriptgraphinverseinequalityjsxgraph

Inverse: true doesn't plot the right graph for all inequalities


I was trying to plot a graph for inequality 5x + 2y -5 >= 0.

So as expected and verified from Desmos's Graph I am getting:

Desmos graph for equation 5x + 2y - 5 >= 0

I was getting this exact same plot using JSXGraph:

JSXGraph plot for equation 5x + 2y - 5 >= 0

Code for creating this graph:

var board = JXG.JSXGraph.initBoard('graphDiv',{axis:true, boundingbox:[-4, 5, 4, -3]});  //Creates the cartesian graph

var input = [5,2,-5];  //5x + 2y - 5 = 0

line = board.create('line', [input[2],input[0],input[1]], {fixed: true });
ineq = board.create('inequality', [line], {inverse:true});

But the problem arised when I was trying for the inverted inequality. But my application was such that the coefficients for multiple line equations will be different and the corresponding lines are created via for loop. So, for the inequality: -5x -2y +5 >=0, following are the results:

As expected and verified from Desmos:

Desmos graph for equation -5x - 2y + 5 >= 0

And as seen from JSXGraph:

JSXGraph for equation: -5x - 2y + 5 >= 0

Nopes, I haven't uploaded the same image twice. I am getting the same plot again.

The code for this part goes as:

var board = JXG.JSXGraph.initBoard('graphDiv',{axis:true, boundingbox:[-4, 5, 4, -3]});  //Creates the cartesian graph

var input = [-5,-2,5];  //-5x - 2y + 5 = 0

line = board.create('line', [input[2],input[0],input[1]], {fixed: true });
ineq = board.create('inequality', [line], {inverse:true});

Why am I not getting the inverted region highlighted in this JSXGraph? Is there any way I can display it the other way round?

I tried removing inverse: true and I am getting the right region highlighted for the second equation but I am getting the wrong one in case of the first equation. Why isn't inverse: true working in both the situations as I have correctly changed the coefficients.

As I already mentioned, in my application, I have equations of multiple lines and I cannot specify whether inverse: true has to be included or not for each line individually. Using a for loop is the only way out.


Solution

  • I had tried using a workaround earlier which worked out only for some inequalities. So I commented on this issue on JSXGraph's Github Repository. Thanks to the efficient development team and the speedy responses, this bug has now been fixed by their contributor Alfred Wassermann.

    Yayy now I can draw the right inequalities!

    This bug fix will be available in the next release. Till then you'll have to do the build the jsxgraphcore.js file and use it in your webapp.