makaip / mathematix

A nodeblock-based math webapp.
https://makaip.github.io/mathematix/
GNU General Public License v3.0
4 stars 0 forks source link

Non-continuous graphs render as continuous #7

Closed makaip closed 8 months ago

makaip commented 8 months ago

When plotting graphs that contain asymptotes, such as 1/x, or discontinuous functions, such as 2 % x, the functions still render as connected. This is because all graphs are assumed to be continuous, which causes gaps to be rendered as solid. The function for plotting functions can be found in draw.js on lines 57 to 73.

for (const funcString of functionsToPlot) {
    rctx.beginPath();

    for (let x = 0; x < rcanvasWidth; x++) {
        const realX = (x - rcanvasWidth / 2 + roffsetX) * 0.025;
        const realY = -evaluateFunction(funcString, realX) * 40 + (rcanvasHeight / 2 - roffsetY);

        if (x === 0) {
            rctx.moveTo(x, realY);
        } else {
            rctx.lineTo(x, realY);
        }
    }

    rctx.stroke();
}

A potential solution could entail the utilization of discontinuous function detection algorithms, such as computing a value at n, then computing a value at (n+1), and if (n+1) does not exist, terminate the line and proceed with computing (n+2). This could potentially cause performance issues with rendering, as this would double the number of render calls. When implementing the "equals" node block, we may want to reconsider our rendering methods to align with the paper here.

AlexanderJCS commented 8 months ago

This is mostly fixed except for non-x inputs to trigonometric functions. Will close once that's completed

AlexanderJCS commented 8 months ago

This is mostly fixed with my changes. I am going to close this issue, but we may re-open it since my changes are not 100% bug-free (but they're good enough for now)