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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
</html>
|
|
|
|
| 1 |
<!doctype html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="utf-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
| 6 |
+
<style>body { margin: 0; } [hidden] { display: none !important; }</style>
|
| 7 |
+
<title>Deformation Gradient Explorer</title>
|
| 8 |
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
| 9 |
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
| 10 |
+
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans+Condensed:wght@500;600&family=IBM+Plex+Sans:wght@400;500&display=swap">
|
| 11 |
+
<style>
|
| 12 |
+
/* Layout: drafting-sheet tool. Plot (the deformed square) on the left, controls + tensors on the right; stacks on phones.
|
| 13 |
+
Column 1 of F is coded orange, column 2 violet, in the plot and in the matrices. */
|
| 14 |
+
:root {
|
| 15 |
+
--bg: #eef1f4; /* drafting sheet */
|
| 16 |
+
--panel: #f9fafb;
|
| 17 |
+
--fg: #1b2530;
|
| 18 |
+
--muted: #5d6a78;
|
| 19 |
+
--line: #cfd6de;
|
| 20 |
+
--grid: #dde3e9;
|
| 21 |
+
--ref: #8a96a3; /* reference configuration */
|
| 22 |
+
--body: #0f6e78; /* deformed body */
|
| 23 |
+
--body-fill: rgba(15, 110, 120, 0.13);
|
| 24 |
+
--c1: #c2570c; /* first column of F = image of e1 */
|
| 25 |
+
--c2: #6b3fc4; /* second column of F = image of e2 */
|
| 26 |
+
--flash: rgba(194, 87, 12, 0.22);
|
| 27 |
+
--font-display: "IBM Plex Sans Condensed", "Arial Narrow", system-ui, sans-serif;
|
| 28 |
+
--font-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
|
| 29 |
+
--font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
|
| 30 |
+
}
|
| 31 |
+
@media (prefers-color-scheme: dark) {
|
| 32 |
+
:root:not([data-theme="light"]) {
|
| 33 |
+
--bg: #12181e; --panel: #19212a; --fg: #e3e8ee; --muted: #93a0ad; --line: #2c3743; --grid: #222c36;
|
| 34 |
+
--ref: #6f7c89; --body: #4fc1cc; --body-fill: rgba(79, 193, 204, 0.14); --c1: #f08a3c; --c2: #a98bf0;
|
| 35 |
+
--flash: rgba(240, 138, 60, 0.28); color-scheme: dark;
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
:root[data-theme="dark"] {
|
| 39 |
+
--bg: #12181e; --panel: #19212a; --fg: #e3e8ee; --muted: #93a0ad; --line: #2c3743; --grid: #222c36;
|
| 40 |
+
--ref: #6f7c89; --body: #4fc1cc; --body-fill: rgba(79, 193, 204, 0.14); --c1: #f08a3c; --c2: #a98bf0;
|
| 41 |
+
--flash: rgba(240, 138, 60, 0.28); color-scheme: dark;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
* { box-sizing: border-box; }
|
| 45 |
+
body {
|
| 46 |
+
background: var(--bg); color: var(--fg); font-family: var(--font-body); font-size: 15px; line-height: 1.5;
|
| 47 |
+
padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
|
| 48 |
+
padding-block: 20px 32px;
|
| 49 |
+
}
|
| 50 |
+
.wrap { max-width: 1180px; margin: 0 auto; display: grid; gap: 18px; }
|
| 51 |
+
header { display: grid; gap: 4px; }
|
| 52 |
+
h1 { font-family: var(--font-display); font-weight: 600; font-size: clamp(1.6rem, 3.2vw, 2.2rem); line-height: 1.1; margin: 0; letter-spacing: 0.01em; text-wrap: balance; }
|
| 53 |
+
.sub { color: var(--muted); margin: 0; max-width: 70ch; }
|
| 54 |
+
.sub code, .note code { font-family: var(--font-mono); font-size: 0.92em; }
|
| 55 |
+
|
| 56 |
+
.main { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 18px; align-items: start; }
|
| 57 |
+
@media (max-width: 860px) { .main { grid-template-columns: minmax(0, 1fr); } }
|
| 58 |
+
|
| 59 |
+
.plot { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 10px; display: grid; gap: 8px; min-width: 0; }
|
| 60 |
+
.plot svg { width: 100%; height: auto; aspect-ratio: 1 / 1; max-width: 100%; display: block; }
|
| 61 |
+
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 0.82rem; color: var(--muted); }
|
| 62 |
+
.legend span { display: inline-flex; align-items: center; gap: 6px; }
|
| 63 |
+
.sw { width: 18px; height: 0; border-top: 2px solid; display: inline-block; }
|
| 64 |
+
|
| 65 |
+
.side { display: grid; gap: 14px; min-width: 0; }
|
| 66 |
+
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 14px; display: grid; gap: 12px; min-width: 0; }
|
| 67 |
+
.label { font-family: var(--font-display); font-weight: 600; font-size: 0.78rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 0; }
|
| 68 |
+
|
| 69 |
+
.formula { font-family: var(--font-mono); font-size: 0.86rem; color: var(--muted); margin: 0; overflow-x: auto; white-space: nowrap; }
|
| 70 |
+
.sliders { display: grid; gap: 10px; }
|
| 71 |
+
.slider { display: grid; grid-template-columns: 7.2rem minmax(0, 1fr) 4.4rem; align-items: center; gap: 10px; }
|
| 72 |
+
.slider label { font-size: 0.9rem; }
|
| 73 |
+
.slider label b { font-family: var(--font-mono); font-weight: 500; }
|
| 74 |
+
.slider output { font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; font-size: 0.9rem; }
|
| 75 |
+
input[type="range"] { width: 100%; accent-color: var(--body); }
|
| 76 |
+
input[type="range"]:focus-visible, button:focus-visible, input[type="checkbox"]:focus-visible { outline: 2px solid var(--body); outline-offset: 2px; }
|
| 77 |
+
|
| 78 |
+
.presets { display: flex; flex-wrap: wrap; gap: 8px; }
|
| 79 |
+
button {
|
| 80 |
+
font: inherit; font-size: 0.85rem; color: var(--fg); background: transparent; border: 1px solid var(--line);
|
| 81 |
+
border-radius: 999px; padding: 5px 12px; cursor: pointer;
|
| 82 |
+
}
|
| 83 |
+
button:hover { border-color: var(--body); color: var(--body); }
|
| 84 |
+
.toggles { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 0.88rem; }
|
| 85 |
+
.toggles label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
|
| 86 |
+
|
| 87 |
+
.tensors { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
|
| 88 |
+
@media (max-width: 420px) { .tensors { grid-template-columns: minmax(0, 1fr); } }
|
| 89 |
+
.tensor { display: grid; gap: 4px; min-width: 0; }
|
| 90 |
+
.tensor .name { font-family: var(--font-mono); font-size: 0.9rem; }
|
| 91 |
+
.tensor .what { font-size: 0.78rem; color: var(--muted); }
|
| 92 |
+
.mat {
|
| 93 |
+
display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px 10px; padding: 6px 12px;
|
| 94 |
+
border-left: 2px solid var(--fg); border-right: 2px solid var(--fg); border-radius: 4px;
|
| 95 |
+
font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 0.98rem; text-align: right;
|
| 96 |
+
}
|
| 97 |
+
.mat span { padding: 1px 3px; border-radius: 3px; transition: background-color 0.6s ease; }
|
| 98 |
+
.mat span.flash { background: var(--flash); transition: none; }
|
| 99 |
+
#F .c1 { color: var(--c1); } #F .c2 { color: var(--c2); }
|
| 100 |
+
|
| 101 |
+
.scalars { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px 14px; margin: 0; }
|
| 102 |
+
.scalars div { display: grid; gap: 0; }
|
| 103 |
+
.scalars dt { font-size: 0.78rem; color: var(--muted); }
|
| 104 |
+
.scalars dd { margin: 0; font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 1rem; }
|
| 105 |
+
|
| 106 |
+
.note { font-size: 0.88rem; color: var(--muted); margin: 0; }
|
| 107 |
+
.note b { color: var(--fg); font-weight: 500; }
|
| 108 |
+
ol.try { margin: 0; padding-left: 1.2rem; display: grid; gap: 4px; font-size: 0.9rem; }
|
| 109 |
+
@media (prefers-reduced-motion: reduce) { .mat span { transition: none; } }
|
| 110 |
+
</style>
|
| 111 |
+
</head>
|
| 112 |
+
<body>
|
| 113 |
+
<div class="wrap">
|
| 114 |
+
<header>
|
| 115 |
+
<h1>Deformation Gradient Explorer</h1>
|
| 116 |
+
<p class="sub">A unit square is mapped by <code>x = F X</code>. Drag the sliders and watch which tensors change.
|
| 117 |
+
<code>F</code> holds stretch <em>and</em> rotation; <code>C = FᵀF</code> and <code>E</code> keep only the change of shape.</p>
|
| 118 |
+
</header>
|
| 119 |
+
|
| 120 |
+
<div class="main">
|
| 121 |
+
<section class="plot" aria-label="Reference and deformed square">
|
| 122 |
+
<svg id="svg" viewBox="-2 -2 4 4" role="img" aria-label="Reference square, deformed square, images of the unit edges and of a circle of fibres"></svg>
|
| 123 |
+
<div class="legend">
|
| 124 |
+
<span><i class="sw" style="border-top-style:dashed;border-color:var(--ref)"></i>reference square</span>
|
| 125 |
+
<span><i class="sw" style="border-color:var(--body)"></i>deformed square</span>
|
| 126 |
+
<span><i class="sw" style="border-color:var(--c1)"></i>F e₁ = 1st column of F</span>
|
| 127 |
+
<span><i class="sw" style="border-color:var(--c2)"></i>F e₂ = 2nd column of F</span>
|
| 128 |
+
<span id="lg-ell"><i class="sw" style="border-color:var(--body);border-top-style:dotted"></i>circle of fibres → ellipse, principal stretches</span>
|
| 129 |
+
</div>
|
| 130 |
+
</section>
|
| 131 |
+
|
| 132 |
+
<div class="side">
|
| 133 |
+
<section class="card" aria-label="Controls">
|
| 134 |
+
<p class="label">Deformation</p>
|
| 135 |
+
<p class="formula">F = R(θ) · [[λ₁, γ], [0, λ₂]] — stretch/shear first, then rotate</p>
|
| 136 |
+
<div class="sliders">
|
| 137 |
+
<div class="slider"><label for="th">rotation <b>θ</b></label><input id="th" type="range" min="-180" max="180" step="1" value="30"><output id="th-o" for="th"></output></div>
|
| 138 |
+
<div class="slider"><label for="l1">stretch <b>λ₁</b> (x)</label><input id="l1" type="range" min="0.4" max="2.5" step="0.01" value="1.5"><output id="l1-o" for="l1"></output></div>
|
| 139 |
+
<div class="slider"><label for="l2">stretch <b>λ₂</b> (y)</label><input id="l2" type="range" min="0.4" max="2.5" step="0.01" value="1"><output id="l2-o" for="l2"></output></div>
|
| 140 |
+
<div class="slider"><label for="g">shear <b>γ</b></label><input id="g" type="range" min="-1" max="1" step="0.01" value="0"><output id="g-o" for="g"></output></div>
|
| 141 |
+
</div>
|
| 142 |
+
<div class="presets" role="group" aria-label="Presets">
|
| 143 |
+
<button type="button" data-p="0,1,1,0">Undeformed</button>
|
| 144 |
+
<button type="button" data-p="45,1,1,0">Rigid rotation 45°</button>
|
| 145 |
+
<button type="button" data-p="0,1.5,1,0">Stretch x 1.5</button>
|
| 146 |
+
<button type="button" data-p="0,1,1,0.8">Simple shear</button>
|
| 147 |
+
<button type="button" data-p="60,1.5,0.8,0">Stretch + rotate</button>
|
| 148 |
+
</div>
|
| 149 |
+
<div class="toggles">
|
| 150 |
+
<label for="t-ell"><input id="t-ell" type="checkbox" checked>circle of fibres</label>
|
| 151 |
+
<label for="t-grid"><input id="t-grid" type="checkbox" checked>grid</label>
|
| 152 |
+
</div>
|
| 153 |
+
</section>
|
| 154 |
+
|
| 155 |
+
<section class="card" aria-label="Tensors">
|
| 156 |
+
<p class="label">Tensors (cells flash when they change)</p>
|
| 157 |
+
<div class="tensors">
|
| 158 |
+
<div class="tensor"><span class="name">F = ∂x/∂X</span><span class="what">deformation gradient: stretch + rotation</span><div class="mat" id="F"></div></div>
|
| 159 |
+
<div class="tensor"><span class="name">C = FᵀF</span><span class="what">right Cauchy–Green: squared stretches, no rotation</span><div class="mat" id="C"></div></div>
|
| 160 |
+
<div class="tensor"><span class="name">E = ½(C − I)</span><span class="what">Green–Lagrange strain (exact)</span><div class="mat" id="E"></div></div>
|
| 161 |
+
<div class="tensor"><span class="name">ε = sym(F − I)</span><span class="what">linear (small) strain</span><div class="mat" id="eps"></div></div>
|
| 162 |
+
</div>
|
| 163 |
+
<dl class="scalars">
|
| 164 |
+
<div><dt>J = det F (area ratio)</dt><dd id="J"></dd></div>
|
| 165 |
+
<div><dt>rotation in F (polar R)</dt><dd id="rot"></dd></div>
|
| 166 |
+
<div><dt>principal stretches λ_I, λ_II</dt><dd id="ps"></dd></div>
|
| 167 |
+
<div><dt>‖E − ε‖ (linear-strain error)</dt><dd id="err"></dd></div>
|
| 168 |
+
</dl>
|
| 169 |
+
</section>
|
| 170 |
+
|
| 171 |
+
<section class="card" aria-label="What to try">
|
| 172 |
+
<p class="label">Try this</p>
|
| 173 |
+
<ol class="try">
|
| 174 |
+
<li>Press <b>Rigid rotation 45°</b> and drag <b>θ</b>: <code>F</code> changes, <code>C</code> = I and <code>E</code> = 0 stay put, but <code>ε</code> is not zero.</li>
|
| 175 |
+
<li>Set λ₁ = 1.5, then drag <b>θ</b>: <code>F</code> keeps changing, <code>C</code> and <code>E</code> do not. The shape is the same, only turned.</li>
|
| 176 |
+
<li>Read <code>F</code> off the plot: its columns are where the edges e₁ and e₂ went (orange and violet arrows).</li>
|
| 177 |
+
<li><b>Simple shear</b>: <code>E₁₂ = γ/2</code> changes the right angle; <code>E₂₂ = γ²/2</code> is a stretch the linear strain misses.</li>
|
| 178 |
+
</ol>
|
| 179 |
+
</section>
|
| 180 |
+
</div>
|
| 181 |
+
</div>
|
| 182 |
+
</div>
|
| 183 |
+
|
| 184 |
+
<script>
|
| 185 |
+
(function () {
|
| 186 |
+
const $ = (id) => document.getElementById(id);
|
| 187 |
+
const ids = ["th", "l1", "l2", "g"];
|
| 188 |
+
const NS = "http://www.w3.org/2000/svg";
|
| 189 |
+
const svg = $("svg");
|
| 190 |
+
const prev = {};
|
| 191 |
+
|
| 192 |
+
function fmt(v, d = 3) {
|
| 193 |
+
const s = (Math.abs(v) < 0.5 * Math.pow(10, -d) ? 0 : v).toFixed(d);
|
| 194 |
+
return (s.startsWith("-") ? "−" + s.slice(1) : " " + s); // figure space keeps columns aligned
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
function state() {
|
| 198 |
+
return { th: +$("th").value, l1: +$("l1").value, l2: +$("l2").value, g: +$("g").value };
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
function compute(p) {
|
| 202 |
+
const t = p.th * Math.PI / 180, c = Math.cos(t), s = Math.sin(t);
|
| 203 |
+
const F = [[c * p.l1, c * p.g - s * p.l2], [s * p.l1, s * p.g + c * p.l2]];
|
| 204 |
+
const C = [[F[0][0] ** 2 + F[1][0] ** 2, F[0][0] * F[0][1] + F[1][0] * F[1][1]], [0, F[0][1] ** 2 + F[1][1] ** 2]];
|
| 205 |
+
C[1][0] = C[0][1];
|
| 206 |
+
const E = [[(C[0][0] - 1) / 2, C[0][1] / 2], [C[1][0] / 2, (C[1][1] - 1) / 2]];
|
| 207 |
+
const eps = [[F[0][0] - 1, (F[0][1] + F[1][0]) / 2], [(F[0][1] + F[1][0]) / 2, F[1][1] - 1]];
|
| 208 |
+
const J = F[0][0] * F[1][1] - F[0][1] * F[1][0];
|
| 209 |
+
const rot = Math.atan2(F[1][0] - F[0][1], F[0][0] + F[1][1]) * 180 / Math.PI; // polar decomposition F = R U
|
| 210 |
+
const tr = C[0][0] + C[1][1], det = C[0][0] * C[1][1] - C[0][1] ** 2;
|
| 211 |
+
const disc = Math.sqrt(Math.max(tr * tr / 4 - det, 0));
|
| 212 |
+
const lamI = Math.sqrt(tr / 2 + disc), lamII = Math.sqrt(Math.max(tr / 2 - disc, 0));
|
| 213 |
+
const psi = 0.5 * Math.atan2(2 * C[0][1], C[0][0] - C[1][1]); // principal direction N_I (reference)
|
| 214 |
+
const err = Math.hypot(E[0][0] - eps[0][0], E[0][1] - eps[0][1], E[1][0] - eps[1][0], E[1][1] - eps[1][1]);
|
| 215 |
+
return { F, C, E, eps, J, rot, lamI, lamII, psi, err };
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
function showMat(id, M, cls) {
|
| 219 |
+
const el = $(id);
|
| 220 |
+
if (!el.children.length) {
|
| 221 |
+
for (let i = 0; i < 4; i++) {
|
| 222 |
+
const sp = document.createElement("span");
|
| 223 |
+
if (cls) sp.className = i % 2 === 0 ? "c1" : "c2";
|
| 224 |
+
el.appendChild(sp);
|
| 225 |
+
}
|
| 226 |
+
}
|
| 227 |
+
const vals = [M[0][0], M[0][1], M[1][0], M[1][1]];
|
| 228 |
+
vals.forEach((v, i) => {
|
| 229 |
+
const sp = el.children[i], key = id + i, txt = fmt(v);
|
| 230 |
+
if (prev[key] !== undefined && prev[key] !== txt) {
|
| 231 |
+
sp.classList.remove("flash"); void sp.offsetWidth; sp.classList.add("flash");
|
| 232 |
+
clearTimeout(sp._t); sp._t = setTimeout(() => sp.classList.remove("flash"), 60);
|
| 233 |
+
}
|
| 234 |
+
prev[key] = txt; sp.textContent = txt;
|
| 235 |
+
});
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
function el(tag, attrs, parent) {
|
| 239 |
+
const e = document.createElementNS(NS, tag);
|
| 240 |
+
for (const k in attrs) e.setAttribute(k, attrs[k]);
|
| 241 |
+
(parent || svg).appendChild(e);
|
| 242 |
+
return e;
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
function arrow(g, x, y, color, head) {
|
| 246 |
+
const L = Math.hypot(x, y);
|
| 247 |
+
el("line", { x1: 0, y1: 0, x2: x, y2: y, stroke: color, "stroke-width": 2.4, "vector-effect": "non-scaling-stroke" }, g);
|
| 248 |
+
if (L < 1e-6) return;
|
| 249 |
+
const ux = x / L, uy = y / L, h = Math.min(head, 0.45 * L), w = 0.45 * h;
|
| 250 |
+
const bx = x - ux * h, by = y - uy * h;
|
| 251 |
+
el("polygon", { points: `${x},${y} ${bx - uy * w},${by + ux * w} ${bx + uy * w},${by - ux * w}`, fill: color }, g);
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
function draw(p, r) {
|
| 255 |
+
const css = getComputedStyle(document.documentElement);
|
| 256 |
+
const col = (n) => css.getPropertyValue(n).trim();
|
| 257 |
+
const F = r.F, map = (X, Y) => [F[0][0] * X + F[0][1] * Y, F[1][0] * X + F[1][1] * Y];
|
| 258 |
+
const sq = [[0, 0], [1, 0], [1, 1], [0, 1]];
|
| 259 |
+
const def = sq.map(([a, b]) => map(a, b));
|
| 260 |
+
const ext = Math.max(1.2, ...def.flat().map(Math.abs)) + 0.35;
|
| 261 |
+
const R = Math.max(2, Math.ceil(ext * 2) / 2); // view grows in half-unit steps
|
| 262 |
+
svg.setAttribute("viewBox", `${-R} ${-R} ${2 * R} ${2 * R}`);
|
| 263 |
+
svg.textContent = "";
|
| 264 |
+
const g = el("g", { transform: "scale(1,-1)" }); // y up
|
| 265 |
+
const head = 0.075 * R;
|
| 266 |
+
|
| 267 |
+
if ($("t-grid").checked) {
|
| 268 |
+
for (let k = -Math.floor(R); k <= Math.floor(R); k++) {
|
| 269 |
+
el("line", { x1: k, y1: -R, x2: k, y2: R, stroke: col("--grid"), "stroke-width": k === 0 ? 1.4 : 1, "vector-effect": "non-scaling-stroke" }, g);
|
| 270 |
+
el("line", { x1: -R, y1: k, x2: R, y2: k, stroke: col("--grid"), "stroke-width": k === 0 ? 1.4 : 1, "vector-effect": "non-scaling-stroke" }, g);
|
| 271 |
+
}
|
| 272 |
+
}
|
| 273 |
+
el("polygon", { points: sq.map((q) => q.join(",")).join(" "), fill: "none", stroke: col("--ref"), "stroke-width": 1.5, "stroke-dasharray": "5 4", "vector-effect": "non-scaling-stroke" }, g);
|
| 274 |
+
el("polygon", { points: def.map((q) => q.join(",")).join(" "), fill: col("--body-fill"), stroke: col("--body"), "stroke-width": 2.2, "vector-effect": "non-scaling-stroke" }, g);
|
| 275 |
+
|
| 276 |
+
if ($("t-ell").checked) {
|
| 277 |
+
const rad = 0.3, cx = 0.5, cy = 0.5, pts = [], ref = [];
|
| 278 |
+
for (let i = 0; i <= 72; i++) {
|
| 279 |
+
const a = (2 * Math.PI * i) / 72, X = cx + rad * Math.cos(a), Y = cy + rad * Math.sin(a);
|
| 280 |
+
ref.push(`${X},${Y}`); pts.push(map(X, Y).join(","));
|
| 281 |
+
}
|
| 282 |
+
el("polyline", { points: ref.join(" "), fill: "none", stroke: col("--ref"), "stroke-width": 1, "stroke-dasharray": "2 3", "vector-effect": "non-scaling-stroke" }, g);
|
| 283 |
+
el("polyline", { points: pts.join(" "), fill: "none", stroke: col("--body"), "stroke-width": 1.4, "stroke-dasharray": "2 3", "vector-effect": "non-scaling-stroke" }, g);
|
| 284 |
+
const [ccx, ccy] = map(cx, cy);
|
| 285 |
+
[[r.psi, r.lamI], [r.psi + Math.PI / 2, r.lamII]].forEach(([ang, lam]) => {
|
| 286 |
+
const [dx, dy] = map(Math.cos(ang), Math.sin(ang)), L = Math.hypot(dx, dy) || 1;
|
| 287 |
+
const sx = (dx / L) * lam * rad, sy = (dy / L) * lam * rad; // R N_i scaled by lambda_i * r
|
| 288 |
+
el("line", { x1: ccx - sx, y1: ccy - sy, x2: ccx + sx, y2: ccy + sy, stroke: col("--body"), "stroke-width": 1.4, "vector-effect": "non-scaling-stroke" }, g);
|
| 289 |
+
});
|
| 290 |
+
}
|
| 291 |
+
el("line", { x1: 0, y1: 0, x2: 1, y2: 0, stroke: col("--ref"), "stroke-width": 1, "vector-effect": "non-scaling-stroke" }, g);
|
| 292 |
+
el("line", { x1: 0, y1: 0, x2: 0, y2: 1, stroke: col("--ref"), "stroke-width": 1, "vector-effect": "non-scaling-stroke" }, g);
|
| 293 |
+
arrow(g, F[0][0], F[1][0], col("--c1"), head);
|
| 294 |
+
arrow(g, F[0][1], F[1][1], col("--c2"), head);
|
| 295 |
+
|
| 296 |
+
const t = el("g", {});
|
| 297 |
+
const lab = (x, y, s, c) => {
|
| 298 |
+
const e = el("text", { x, y: -y, fill: c, "font-size": 0.055 * 2 * R, "font-family": "IBM Plex Mono, ui-monospace, monospace", "text-anchor": "middle", "dominant-baseline": "middle" }, t);
|
| 299 |
+
e.textContent = s;
|
| 300 |
+
};
|
| 301 |
+
const lp = (x, y, k) => { const L = Math.hypot(x, y) || 1; return [x + (x / L) * k, y + (y / L) * k]; };
|
| 302 |
+
lab(...lp(F[0][0], F[1][0], 0.12 * R), "F e₁", col("--c1"));
|
| 303 |
+
lab(...lp(F[0][1], F[1][1], 0.12 * R), "F e₂", col("--c2"));
|
| 304 |
+
lab(1.0, -0.16 * R, "e₁", col("--ref"));
|
| 305 |
+
lab(-0.12 * R, 1.0, "e₂", col("--ref"));
|
| 306 |
+
if ($("t-grid").checked) {
|
| 307 |
+
for (let k = -Math.floor(R); k <= Math.floor(R); k++) if (k) {
|
| 308 |
+
lab(k, -0.06 * R, String(k), col("--muted"));
|
| 309 |
+
}
|
| 310 |
+
}
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
function update() {
|
| 314 |
+
const p = state();
|
| 315 |
+
$("th-o").value = p.th + "°";
|
| 316 |
+
$("l1-o").value = p.l1.toFixed(2);
|
| 317 |
+
$("l2-o").value = p.l2.toFixed(2);
|
| 318 |
+
$("g-o").value = fmt(p.g, 2);
|
| 319 |
+
const r = compute(p);
|
| 320 |
+
showMat("F", r.F, true); showMat("C", r.C); showMat("E", r.E); showMat("eps", r.eps);
|
| 321 |
+
$("J").textContent = fmt(r.J);
|
| 322 |
+
$("rot").textContent = fmt(r.rot, 1) + "°";
|
| 323 |
+
$("ps").textContent = r.lamI.toFixed(3) + ", " + r.lamII.toFixed(3);
|
| 324 |
+
$("err").textContent = fmt(r.err);
|
| 325 |
+
$("lg-ell").hidden = !$("t-ell").checked;
|
| 326 |
+
draw(p, r);
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
ids.forEach((id) => $(id).addEventListener("input", update));
|
| 330 |
+
["t-ell", "t-grid"].forEach((id) => $(id).addEventListener("change", update));
|
| 331 |
+
document.querySelectorAll("[data-p]").forEach((b) => b.addEventListener("click", () => {
|
| 332 |
+
b.dataset.p.split(",").forEach((v, i) => { $(ids[i]).value = v; });
|
| 333 |
+
update();
|
| 334 |
+
}));
|
| 335 |
+
if (window.matchMedia) {
|
| 336 |
+
const mq = window.matchMedia("(prefers-color-scheme: dark)");
|
| 337 |
+
(mq.addEventListener ? mq.addEventListener("change", update) : mq.addListener(update));
|
| 338 |
+
}
|
| 339 |
+
new MutationObserver(update).observe(document.documentElement, { attributes: true, attributeFilter: ["data-theme"] });
|
| 340 |
+
update();
|
| 341 |
+
})();
|
| 342 |
+
</script>
|
| 343 |
+
</body>
|
| 344 |
</html>
|