~smitop/eigen.fun

62c1b6313fe97cce4d12d4708a000cf8af12164f — Smitty 3 years ago 6410767
show line when no grid
1 files changed, 18 insertions(+), 0 deletions(-)

M public/script.js
M public/script.js => public/script.js +18 -0
@@ 273,7 273,25 @@ function render() {
    ctx.clearRect(0, 0, can.width, can.height);
    const det = getDet();
    if (Math.abs(det) > LOW_DET_THRESH) {
        // full rank, render a grid
        renderGrid(renderOpts, ctx);
    } else {
        const distFromOrigin = [state.ihat, state.jhat].map(vec => Math.abs(vec.reduce((a, b) => a + b))).reduce((a, b) => a + b);
        if (distFromOrigin > 0.1) {
            // rank 1, render a line
            // if det is 0 then ihat's tip, jhat's tip, and the origin will all be on a line
            // but when it's almost 0, do some trickery to get the line to look right

            // TODO: properly extend to screen edges
            const points = [
                transformPoint(state.ihat).map(x => x * 100),
                [0, 0],
                transformPoint(state.jhat).map(x => x * 100),
            ];

            renderLine(renderOpts, "black", false, points[0], points[2], ctx, x => x);
        }
        // draw nothing repersenting the transformation for rank 0
    }

    // unit vectors