GPT is reall good at generating comments and fixing spelling error

This commit is contained in:
2025-12-23 13:28:51 -06:00
parent 9f1555d6e0
commit 9735df3ecb
11 changed files with 917 additions and 355 deletions

100
math.md Normal file
View File

@@ -0,0 +1,100 @@
# Silk Particle Simulation: Mathematical Formulation
## 1. Stream Function
The velocity field is derived from a scalar stream function $\psi(x, y, t)$:
$$
\psi(x, y, t) = \sum_{i=1}^{4} A_i \Psi_i(x, y, t)
$$
where:
$$
\begin{align}
\Psi_1 &= \sin(\omega_1 x + \phi_1(t)) \sin(\omega_1 y) \\
\Psi_2 &= \sin(\omega_2 x) \sin(\omega_2 y + \phi_2(t)) \\
\Psi_3 &= \sin(\omega_3 r + \phi_3(t)), \quad r = \sqrt{(x - 0.5)^2 + (y - 0.5)^2} \\
\Psi_4 &= (x - 0.5)(y - 0.5) \sin(\omega_4 t)
\end{align}
$$
Suggested parameters: $A = (0.3, 0.25, 0.2, 0.15)$, $\omega = (2\pi, 3\pi, 4\pi, 0.5)$, $\phi_i(t) = c_i t$ with $c = (0.5, 0.3, 0.4)$
---
## 2. Velocity Field
Incompressible flow via curl of stream function:
$$
\mathbf{v} = \nabla \times \psi = \left(\frac{\partial \psi}{\partial y}, -\frac{\partial \psi}{\partial x}\right)
$$
This ensures $\nabla \cdot \mathbf{v} = 0$ (divergence-free).
---
## 3. Vorticity (for color)
Scalar vorticity equals the negative Laplacian of the stream function:
$$
\omega = \frac{\partial v_y}{\partial x} - \frac{\partial v_x}{\partial y} = -\nabla^2 \psi = -\left(\frac{\partial^2 \psi}{\partial x^2} + \frac{\partial^2 \psi}{\partial y^2}\right)
$$
---
## 4. Boundary Confinement
Soft quartic potential keeps particles on screen:
$$
V_{\text{boundary}}(x, y) = k \left[(x - 0.5)^4 + (y - 0.5)^4\right]
$$
Boundary force:
$$
\mathbf{F}_{\text{boundary}} = -\nabla V_{\text{boundary}} = -4k\left[(x - 0.5)^3, (y - 0.5)^3\right]
$$
---
## 5. Equations of Motion
Particle position $\mathbf{q} = (x, y)$ evolves as:
$$
\frac{d\mathbf{q}}{dt} = (1 - \alpha)\mathbf{v}(\mathbf{q}, t) + \beta \mathbf{F}_{\text{boundary}}(\mathbf{q})
$$
where $\alpha \approx 0.1$ (damping), $\beta \approx 0.05$ (boundary strength).
---
## 6. RK4 Integration
Fourth-order Runge-Kutta for state $\mathbf{s}$ with derivative $\mathbf{f}(\mathbf{s}, t)$:
$$
\begin{align}
\mathbf{k}_1 &= \mathbf{f}(\mathbf{s}, t) \\
\mathbf{k}_2 &= \mathbf{f}(\mathbf{s} + \tfrac{\Delta t}{2} \mathbf{k}_1, t + \tfrac{\Delta t}{2}) \\
\mathbf{k}_3 &= \mathbf{f}(\mathbf{s} + \tfrac{\Delta t}{2} \mathbf{k}_2, t + \tfrac{\Delta t}{2}) \\
\mathbf{k}_4 &= \mathbf{f}(\mathbf{s} + \Delta t \mathbf{k}_3, t + \Delta t) \\
\mathbf{s}_{\text{next}} &= \mathbf{s} + \tfrac{\Delta t}{6} (\mathbf{k}_1 + 2\mathbf{k}_2 + 2\mathbf{k}_3 + \mathbf{k}_4)
\end{align}
$$
---
## 7. Color Mapping
Map vorticity to HSV hue:
$$
H = \text{mod}\left(\frac{\omega - \omega_{\min}}{\omega_{\max} - \omega_{\min}} \cdot 360°, 360°\right), \quad S = 0.8, \quad V = 0.9
$$
Positive $\omega$ (CCW) → warm colors; negative $\omega$ (CW) → cool colors.