From 389fb3a592832092835da0c2cc1608a57ba5f629 Mon Sep 17 00:00:00 2001 From: LalleSX Date: Sat, 24 Oct 2026 14:18:00 +0200 Subject: Add tests for math rendering and interactive scenes; update navigation and viewport handling - Updated `lab.spec.ts` to navigate directly to the field lesson. - Created `math.spec.ts` with tests for math rendering, error checking, and responsive design. - Added `test4.spec.ts` for interactive scenes, ensuring all questions are functional and accessible. - Modified `vite.config.ts` to keep original question/answer links navigable in production. --- docs/Test_4.md | 63 +++++ docs/Test_Answers.md | 361 +++++++++++++++++++++++++++++ docs/implementation-progress.md | 52 ----- docs/superpowers/plans/2026-10-24-test4.md | 59 +++++ 4 files changed, 483 insertions(+), 52 deletions(-) create mode 100644 docs/Test_4.md create mode 100644 docs/Test_Answers.md delete mode 100644 docs/implementation-progress.md create mode 100644 docs/superpowers/plans/2026-10-24-test4.md (limited to 'docs') diff --git a/docs/Test_4.md b/docs/Test_4.md new file mode 100644 index 0000000..beb7160 --- /dev/null +++ b/docs/Test_4.md @@ -0,0 +1,63 @@ +# Test 4 + +**Test 4A:** Questions 1–3. +**Test 4B:** Questions 4–6. +**Max point:** 100 + 100. + +**NB!** Small sketches may improve the answers in questions 1, 3, 4, 5, 6. + +## 1. (30p) + +What is the work done by the electric force, when $q_0$ is moved from $a$ to $b$? + +## 2. (15p) + +Please write the condition for conservation of the total energy. + +## 3. (55p) + +When $q_0$ moves from $a$ to $b$ in an E-field from a point charge $q$ (“Central field”). + +**a. (30p)** Please derive the work done by the electric force. + +**b. (25p)** The work in above is equal to the drop in the electric potential energy +$U_{\mathrm{e\,pot}\,a} - U_{\mathrm{e\,pot}\,b}$. +What is $U_{\mathrm{e\,pot}\,a}$ and $U_{\mathrm{e\,pot}\,b}$ if $b \to \infty$? + +## 4. (25p) + +Bringing charges together. + +**a. (15p)** What is the total electric potential energy if $q_1, q_2, q_3$ are brought together from infinite? + +**b. (10p)** What is the additional electric potential energy if $q_0$ is brought together with $q_1, q_2, q_3$? + +## 5. (25p) + +When $q_0$ moves from $a$ to $b$ in a uniform E-field. + +**a. (15p)** Please derive the work done by the electric force. + +**b. (10p)** What is $U_{\mathrm{pot}\,a}$ and $U_{\mathrm{pot}\,b}$? + +## 6. (50p) + +The electric dipole in a uniform E-field. + +**a. (10p)** Please derive the torque vector. + +Prove, that the magnitude is + +$$ +\tau = p_e E \sin(\theta), +$$ + +where $\theta = \angle(\vec{p}_e, \vec{E})$. + +**b. (30p)** Please derive the work $W_{ab}$ done by the electric force when the electric dipole rotates from $\theta_a$ to $\theta_b$ and what is $U_{\mathrm{e\,pot}\,a}$ and $U_{\mathrm{e\,pot}\,b}$? + +You don’t have to derive $dW = -\tau\,d\theta$. + +**c. (10p)** Explain why $\theta_a = 90^\circ$ can be used as a reference position for the electric potential energy and write the result for $U_{\mathrm{e\,pot}\,a}$. + +Now find the general expression of $U_{\mathrm{e\,pot}}$ for the electric dipole, also written as a scalar product. diff --git a/docs/Test_Answers.md b/docs/Test_Answers.md new file mode 100644 index 0000000..f08a9cc --- /dev/null +++ b/docs/Test_Answers.md @@ -0,0 +1,361 @@ +# Test 4 – Answers + +We assume electrostatic fields in a vacuum and use: + +$$ +k=\frac{1}{4\pi\varepsilon_0}. +$$ + +Here, $U$ denotes electric potential energy, $V$ denotes electric potential, and $q_0$ is the charge being moved. 4Te_pw14 (1)(1) + +## 1. Work done by the electric force from $a$ to $b$ + +The work is found by integrating the force along the path of the charge: + +$$ +W_{ab}=\int_a^b\vec F_e\cdot d\vec r. +$$ + +Since $\vec F_e=q_0\vec E$, we obtain: + +$$ +\boxed{W_{ab}=q_0\int_a^b\vec E\cdot d\vec r}. +$$ + +The electrostatic force is conservative. The work therefore equals the decrease in potential energy: + +$$ +\boxed{W_{ab}=U_a-U_b=q_0(V_a-V_b)}. +$$ + +Positive work means that the potential energy decreases. + +## 2. Condition for conservation of energy + +The total energy of an **isolated system** is constant: + +$$ +\boxed{\Delta E_{\mathrm{total}}=0}. +$$ + +If only the electric force does work, the sum of kinetic and electric potential energy is conserved: + +$$ +\boxed{K_a+U_a=K_b+U_b}. +$$ + +For a particle of mass $m$: + +$$ +\frac12mv_a^2+U_a=\frac12mv_b^2+U_b. +$$ + +This follows from the work–energy theorem: + +$$ +\Delta K=W_{ab}=-\Delta U. +$$ + +## 3. Motion in the field of a point charge + +### 3a. Derivation of the work + +A fixed point charge $q$ creates the field: + +$$ +\vec E(r)=k\frac{q}{r^2}\hat r. +$$ + +The force on $q_0$ is: + +$$ +\vec F_e=k\frac{qq_0}{r^2}\hat r. +$$ + +Let $r_a$ and $r_b$ be the distances from $q$ to $a$ and $b$, respectively. Since $\hat r\cdot d\vec r=dr$, we obtain: + +$$ +W_{ab} +=kqq_0\int_{r_a}^{r_b}\frac{1}{r^2}\,dr. +$$ + +Thus: + +$$ +W_{ab} +=kqq_0\left[-\frac1r\right]_{r_a}^{r_b}. +$$ + +Therefore: + +$$ +\boxed{W_{ab}=kqq_0\left(\frac1{r_a}-\frac1{r_b}\right)}. +$$ + +The result depends only on the initial and final distances, not on the path taken. + +### 3b. Potential energy with a reference at infinity + +We choose: + +$$ +U(\infty)=0. +$$ + +As $r_b\to\infty$, the work becomes: + +$$ +W_{a\infty}=\frac{kqq_0}{r_a}. +$$ + +Since $W_{a\infty}=U_a-U_\infty$, we obtain: + +$$ +\boxed{U_a=\frac{kqq_0}{r_a}}, +\qquad +\boxed{U_b=U_\infty=0}. +$$ + +The general expression for the potential energy is therefore: + +$$ +\boxed{U(r)=\frac{kqq_0}{r}}. +$$ + +Charges with the same sign give positive potential energy; charges with opposite signs give negative potential energy. + +## 4. Assembling point charges + +Let $r_{ij}$ be the distance between charges $q_i$ and $q_j$. The zero of potential energy is chosen to be when all charges are infinitely far apart. + +### 4a. Total potential energy of $q_1,q_2,q_3$ + +The charges can be assembled one at a time: + +- $q_1$ requires no work, since no other charges are present yet. +- $q_2$ adds the energy $kq_1q_2/r_{12}$. +- $q_3$ adds the energy $kq_1q_3/r_{13}+kq_2q_3/r_{23}$. + +The total potential energy is: + +$$ +\boxed{ +U_{123} +=k\left( +\frac{q_1q_2}{r_{12}} ++\frac{q_1q_3}{r_{13}} ++\frac{q_2q_3}{r_{23}} +\right) +}. +$$ + +Each pair of charges is counted once. + +### 4b. Additional potential energy when adding $q_0$ + +With the three existing charges held in place, adding $q_0$ gives: + +$$ +\boxed{ +\Delta U +=k\left( +\frac{q_0q_1}{r_{01}} ++\frac{q_0q_2}{r_{02}} ++\frac{q_0q_3}{r_{03}} +\right) +}. +$$ + +This can also be written as: + +$$ +\boxed{\Delta U=q_0V_{123}}, +$$ + +where $V_{123}$ is the potential due to $q_1,q_2,q_3$ at the position where $q_0$ is placed. + +## 5. Motion in a uniform electric field + +### 5a. Derivation of the work + +In a uniform field, $\vec E$ is constant: + +$$ +W_{ab}=q_0\int_a^b\vec E\cdot d\vec r +=q_0\vec E\cdot(\vec r_b-\vec r_a). +$$ + +Thus: + +$$ +\boxed{W_{ab}=q_0\vec E\cdot(\vec r_b-\vec r_a)}. +$$ + +If the displacement has magnitude $s$ and the angle between the displacement and the field is $\alpha$: + +$$ +\boxed{W_{ab}=q_0Es\cos\alpha}. +$$ + +Choosing the $x$-axis along the direction of the field gives: + +$$ +\boxed{W_{ab}=q_0E(x_b-x_a)}. +$$ + +### 5b. Potential energy at $a$ and $b$ + +Since $W_{ab}=U_a-U_b$: + +$$ +U_b-U_a=-q_0E(x_b-x_a). +$$ + +A potential energy that satisfies this is: + +$$ +U(x)=-q_0Ex+C. +$$ + +Therefore: + +$$ +\boxed{U_a=-q_0Ex_a+C}, +\qquad +\boxed{U_b=-q_0Ex_b+C}. +$$ + +The constant $C$ is determined by the chosen zero of potential energy. Choosing $U_a=0$ gives: + +$$ +\boxed{U_a=0}, +\qquad +\boxed{U_b=-q_0E(x_b-x_a)}. +$$ + +For a positive charge, the potential energy decreases when it moves in the direction of the field. + +## 6. Electric dipole in a uniform electric field + +A dipole consists of charges $+q$ and $-q$, separated by the vector $\vec d$, which points from the negative charge to the positive charge. + +The dipole moment is defined as: + +$$ +\boxed{\vec p_e=q\vec d}. +$$ + +The angle between $\vec p_e$ and $\vec E$ is denoted by $\theta$. + +### 6a. Derivation of the torque + +The forces on the charges are: + +$$ +\vec F_+=q\vec E, +\qquad +\vec F_-=-q\vec E. +$$ + +The net force is zero, but the forces form a couple. + +Taking the midpoint of the dipole as the origin, the position vectors are: + +$$ +\vec r_+=\frac{\vec d}{2}, +\qquad +\vec r_-=-\frac{\vec d}{2}. +$$ + +The total torque is: + +$$ +\begin{aligned} +\vec\tau +&=\vec r_+\times\vec F_+ ++\vec r_-\times\vec F_-\\ +&=\frac{\vec d}{2}\times q\vec E ++\left(-\frac{\vec d}{2}\right)\times(-q\vec E)\\ +&=q\vec d\times\vec E. +\end{aligned} +$$ + +Thus: + +$$ +\boxed{\vec\tau=\vec p_e\times\vec E}. +$$ + +The magnitude of the cross product gives: + +$$ +\boxed{\tau=p_eE\sin\theta}. +$$ + +The torque tends to align the dipole moment with the field. + +### 6b. Work during rotation from $\theta_a$ to $\theta_b$ + +The torque acts in the direction of decreasing $\theta$. With $\tau=p_eE\sin\theta$ as its magnitude: + +$$ +dW=-\tau\,d\theta. +$$ + +The work is therefore: + +$$ +W_{ab}=-p_eE\int_{\theta_a}^{\theta_b}\sin\theta\,d\theta. +$$ + +Integration gives: + +$$ +\boxed{ +W_{ab}=p_eE(\cos\theta_b-\cos\theta_a) +}. +$$ + +Since $W_{ab}=U_a-U_b$, the potential energy can be written as: + +$$ +U(\theta)=-p_eE\cos\theta+C. +$$ + +Therefore: + +$$ +\boxed{U_a=-p_eE\cos\theta_a+C}, +$$ + +$$ +\boxed{U_b=-p_eE\cos\theta_b+C}. +$$ + +### 6c. Reference at $90^\circ$ and the general expression + +The zero of potential energy can be chosen freely. We choose: + +$$ +\boxed{U_a=U(90^\circ)=0}. +$$ + +At $90^\circ$, the two charges are at the same potential in the uniform field, so their contributions to the total potential energy cancel each other. + +Since $\cos90^\circ=0$, this choice of reference gives $C=0$. Therefore: + +$$ +\boxed{U(\theta)=-p_eE\cos\theta}. +$$ + +Using the dot product, we obtain: + +$$ +\boxed{U=-\vec p_e\cdot\vec E}. +$$ + +| Angle | Orientation | Potential energy | Equilibrium | +|---|---|---|---| +| $0^\circ$ | Dipole moment aligned with the field | $-p_eE$, minimum | Stable | +| $90^\circ$ | Dipole moment perpendicular to the field | $0$ | No equilibrium | +| $180^\circ$ | Dipole moment opposite to the field | $+p_eE$, maximum | Unstable | \ No newline at end of file diff --git a/docs/implementation-progress.md b/docs/implementation-progress.md deleted file mode 100644 index f4a745a..0000000 --- a/docs/implementation-progress.md +++ /dev/null @@ -1,52 +0,0 @@ -# Implementation progress — PLAN.md - -The user asks for educational 3D graphics for eight subjects. PLAN.md is the -subject specification; no separate design or implementation spec exists. - -Ruling: Implement the eight subjects as selectable experiments in the existing -Three.js app, sharing a scene host and parameter/readout interface. This gives -each topic an interactive visual immediately. The models are idealizations, -explained in the UI, rather than general field/circuit/quantum solvers. - -Ruling: Continue in this directory because `.git` is an empty managed mount, -not a usable Git repository; worktree/commit scripts cannot run here. - -Pre-flight: Potential and energy share Coulomb models; capacitance and -permittivity share a parallel-plate model; current and semiconductors share -carrier constants. All physics functions use SI units and rendering handles -unit conversion and illustrative scales. - -- Baseline: existing 3 physics tests pass. -- [x] Electrostatics: charge/force/field, flux, energy, potential/gradient. -- [x] Matter/circuits: capacitance, dielectrics, current, semiconductors. -- [x] Eight experiment definitions and educational UI. -- [x] Eight 3D scenes, interaction, animation, cleanup. -- [x] Tests, browser checks, build, README. - -Implementation: -- Electrostatics complete: force/field, exact enclosed-charge flux (surface - singularity disclosed), interaction energy/work, potential and probe gradient. -- Matter/circuits complete: parallel plates, fixed-V/fixed-Q dielectrics, - Ohmic wire with signed drift, intrinsic/n/p silicon equilibrium/bands. -- UI and eight scenes complete: independent settings, deep links/history, - reset, pause/reduced motion, responsive layout and WebGL fallback. -- Renderer rebuilds are coalesced; obsolete GPU resources are disposed. -- Visual inspection: field, potential, capacitance and semiconductor screenshots - checked. Labels changed to stable screen sizes for readability. - -Final review: fresh read-only reviewer approved the current implementation; -no Critical or Important findings. -- Model direction-only capacitor-arrow disclosure was already added during - implementation and resolves the reviewer's corresponding suggestion. -- Final: minor (deferred): browser pause test verifies the state/button; - pixel comparisons proving actual animation cessation are not yet included. -- Final: minor (deferred): finite-difference potential-gradient unit test covers - one charge along x; add multiple sources/off-axis components when expanding. -- Build has a non-fatal Three.js bundle-size advisory (~598 kB minified, - ~153 kB gzip). No deployment or code-splitting requirement in PLAN.md. - -Final verification: 20/20 unit tests, 10/10 Chromium browser tests, strict -TypeScript and Vite production build pass after the final label adjustment. -All eight scenes were checked for rendered geometry and browser exceptions. -The app remains served on http://localhost:5173. No Git integration action -was available or required in this non-repository workspace. diff --git a/docs/superpowers/plans/2026-10-24-test4.md b/docs/superpowers/plans/2026-10-24-test4.md new file mode 100644 index 0000000..278ab0b --- /dev/null +++ b/docs/superpowers/plans/2026-10-24-test4.md @@ -0,0 +1,59 @@ +# Test 4 in 3D Implementation Plan + +> **For agentic workers:** Use superpowers:executing-plans to implement this plan task by task. + +**Goal:** Represent every question and answer in `docs/Test_4.md` and `docs/Test_Answers.md` through an educational, interactive 3D lesson. + +**Architecture:** Extend the existing TypeScript/Three.js lab with a separate Test 4 collection. Share the renderer and parameter UI; keep test physics, lesson content, and scene construction in focused modules. Native execution in the current checkout; the user delegated design and implementation choices. + +**Tech Stack:** Existing Three.js, TypeScript, Vite, Vitest, Playwright; no new dependencies. + +**Spec:** The two source documents above and the design below. + +## Design and constraints + +- Six lessons, with exact question scope, all subparts and original marks: 4A = 100 points, 4B = 100 points. +- Guided lessons were selected as the implementation default after the user said “Choose the details and build it.” An exam-only view hides useful explanation; a disconnected presentation would duplicate the existing renderer. +- Test 4 is the default entry. Existing experiment hash links and all eight experiments remain available through a collection switch. +- Q1: uniform-field straight/curved paths with the same endpoints and work; Q2: repelling charge, energy bars and conserved K + U; Q3: radial motion, inverse-radius energy, reference at infinity; Q4: assemble three charges and add a fourth, showing pair energies once; Q5: angled displacement in a uniform field; Q6: dipole forces, torque, rotation work and energy versus angle. +- Use adjustable progress for inspectable motion; decorative animation respects pause and reduced motion. Explicit physical units and visual scale explanations. Equations and derivations remain usable without WebGL. +- Original questions, step-by-step answers, live numerical examples and a prediction/reveal check in each lesson. Source Markdown is linked from the built app. +- Preserve existing unrelated work and source documents. No publication or repository integration requested. + +## Review focus + +Signed charges and work; arbitrary energy zeros; infinity represented analytically rather than as a finite point; each charge pair counted once; dipole torque sign versus magnitude and unstable equilibrium; mobile overflow; WebGL fallback; collection/history state. + +## Task 1: Physics models + +Files: `src/physics/test4.ts`, `src/physics/test4.test.ts`. + +- [x] Write independent numerical tests for uniform and central work, conservation, pair assembly, dipole torque/work and infinity. +- [x] Run the tests and observe missing model failure. +- [x] Implement SI functions with explicit energy references and domain validation. +- [x] Run physics tests and confirm passing. + +## Task 2: Guided lesson content and scenes + +Files: `src/test4.ts`, `src/scene/test4.ts`, `src/experiments.ts`, `src/scene/experiments.ts`. + +- [x] Add browser checks for lesson selection, parameter changes, answers, graphics and fallback. Initial browser execution required enabling the local server and downloading Chromium into `/tmp`. +- [x] Implement all six lesson definitions with original questions, subparts and derivations. +- [x] Build parameter-linked 3D diagrams with endpoint labels, force/field arrows and energy plots or bars. + +## Task 3: Navigation, learning UI and verification + +Files: `src/main.ts`, `src/style.css`, `tests/test4.spec.ts`, `tests/lab.spec.ts`, `README.md`. + +- [x] Add Test 4/experiment collection navigation, question and solution panels, observation prompts, prediction reveal, previous/next links and retained parameter state. +- [x] Verify direct links, collection/history navigation, mobile overflow, all scenes, resets and WebGL fallback. +- [x] Run `npm test`, `npm run build`, `npm run test:e2e`; inspect desktop and mobile screenshots. +- [x] Obtain an independent code review and address significant findings; document final outcome. + +## Execution record + +Baseline: 20 unit tests passed; production build passed (existing Three.js bundle-size advisory). + +Completed: all six questions and subparts are covered. Independent review confirmed physical and content consistency and found a mobile pagination issue. A new browser regression reproduced the issue, then passed after explicit pagination began focusing and scrolling the new heading. Review polish items were addressed with valid `aria-current="page"`, responsive framing and less crowded mobile labels. Both original Markdown links returned HTTP 200 with their original content from the production preview; assets are emitted as files rather than inlined data URLs. + +Final verification: 25 unit tests passed, 17 browser tests passed, strict TypeScript and production build passed, and `git diff --check` passed. No new dependencies. The existing Three.js bundle-size advisory remains. Work is left in the user's checkout without a commit or publication. -- cgit v1.2.3