From 142117ffa590299695d6004eaa21c9bd936205fa Mon Sep 17 00:00:00 2001 From: Smitty Date: Sun, 27 Jun 2021 15:06:02 -0400 Subject: [PATCH] initial eigen display --- public/index.html | 2 +- public/script.js | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/public/index.html b/public/index.html index 4645808..215824f 100644 --- a/public/index.html +++ b/public/index.html @@ -12,7 +12,7 @@ - + diff --git a/public/script.js b/public/script.js index 2de2468..7502c28 100644 --- a/public/script.js +++ b/public/script.js @@ -14,6 +14,7 @@ let state = { selected: null, curTransition: null, minorLines: true, + eigs: true, snap: false, rendering: { dirty: true, @@ -121,6 +122,24 @@ function getInv() { }; } +function getEigs() { + let mathEigs; + try { + mathEigs = math.eigs(matrix(), 1e-10); + } catch (e) { + return []; + } + const mathVectors = math.transpose(mathEigs.vectors).toArray(); // FIXME: transpose first? + let ret = []; + mathEigs.values.toArray().forEach((value, idx) => { + ret.push({ + value, + vector: mathVectors[idx], + }) + }); + return ret; +} + function renderPoint(renderOpts, point) { point = pointToCanvasCoords(renderOpts, transformPoint(point)); ctx.beginPath(); @@ -297,6 +316,12 @@ function render() { // draw nothing repersenting the transformation for rank 0 } + // eigens + let eigs = getEigs(); + eigs.forEach(({ vector, value }) => { + renderLine(renderOpts, "gray", true, [0, 0], vector, ctx, x => x); // i hat + }); + // unit vectors renderLine(renderOpts, "red", true, [0, 0], [1, 0]); // i hat renderLine(renderOpts, "blue", true, [0, 0], [0, 1]); // j hat -- 2.45.2