Commit 4c92d97
committed
fix(animator): start the underdamped spring from rest
The closed-form underdamped step response is 1 - e^(-zeta*omega*t) *
[cos(omega_d*t) + (zeta*omega/omega_d)*sin(omega_d*t)]. The code feeds
zeta*omega*t/omega_d into sin() instead of omega_d*t — the t was multiplied
into the coefficient instead of the phase. I verified this numerically
against a 400k-step ODE integration of m*x'' + c*x' + k*x = k: the correct
formula matches the integrator to 5 decimals, the repo formula does not.
With the shipped defaults (damping 15, stiffness 100, mass 1, zeta = 0.75),
at the first 60fps frame after the start (t = 0.0167 s) the solver reports
0.10416 of the travel where the physics gives 0.01282 — 8x. Initial velocity
is 6.21/s instead of 0, so the element visibly snaps on frame 1 rather than
easing out of rest, and the overshoot peak is wrong too (1.0194 vs 1.0284).
This affects every spring path in the engine: EasingType::Spring keyframes,
the bounce_in preset (kf_anim_spring, zeta = 0.6, animator.rs:2092),
elastic_in (kf_anim_spring_underdamped, zeta = 0.274, animator.rs:2106), and
every author-supplied spring override applied through
apply_spring_to_motion. spring_settle_time/spring_rest_time (what rustmotion
info reports and what the spring.duration remap divides by) are derived from
the same wrong curve.
Fix: Change the sine argument to (omega_d * t).sin(), keeping the (zeta *
omega / omega_d) coefficient: 1.0 - decay * ((omega_d * t).sin() * (zeta *
omega / omega_d) + (omega_d * t).cos()). Add a regression test asserting the
derivative at t=0 is ~0 (a step response starts at rest) and comparing a few
samples against a numerically integrated reference.
Refs #2201 parent baafd53 commit 4c92d97
2 files changed
Lines changed: 73 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
500 | 500 | | |
501 | 501 | | |
502 | 502 | | |
503 | | - | |
504 | | - | |
| 503 | + | |
505 | 504 | | |
506 | 505 | | |
507 | 506 | | |
| |||
2838 | 2837 | | |
2839 | 2838 | | |
2840 | 2839 | | |
2841 | | - | |
2842 | | - | |
2843 | | - | |
2844 | | - | |
| 2840 | + | |
| 2841 | + | |
| 2842 | + | |
| 2843 | + | |
| 2844 | + | |
| 2845 | + | |
| 2846 | + | |
2845 | 2847 | | |
2846 | 2848 | | |
2847 | | - | |
2848 | | - | |
| 2849 | + | |
| 2850 | + | |
2849 | 2851 | | |
2850 | 2852 | | |
2851 | | - | |
| 2853 | + | |
2852 | 2854 | | |
2853 | | - | |
| 2855 | + | |
2854 | 2856 | | |
2855 | 2857 | | |
2856 | 2858 | | |
| |||
2867 | 2869 | | |
2868 | 2870 | | |
2869 | 2871 | | |
2870 | | - | |
| 2872 | + | |
2871 | 2873 | | |
2872 | 2874 | | |
2873 | 2875 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| 14 | + | |
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
| |||
131 | 133 | | |
132 | 134 | | |
133 | 135 | | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
0 commit comments