Add check for unstable spring parameters

This commit is contained in:
Aaron Smith 2023-09-20 11:39:44 +01:00
parent a543a24865
commit 835f4d429b
2 changed files with 8 additions and 3 deletions

View file

@ -161,6 +161,11 @@ local function spring<T>(source: () -> T, period: number?, damping_ratio: number
local c_c = 2*w_n local c_c = 2*w_n
local c = z * c_c local c = z * c_c
-- todo: is there a solution to this other than upping step frequency?
if c > UPDATE_RATE*2 then -- solver will explode if this is true
throw("spring damping too high, consider reducing damping or increasing period")
end
local data: SpringData<T> = { local data: SpringData<T> = {
k = k, k = k,
c = c, c = c,

View file

@ -48,14 +48,14 @@ local function main()
local reset = "\27[H\27[2J" -- ANSI clear terminal local reset = "\27[H\27[2J" -- ANSI clear terminal
local offset = string.rep("\n", MAX - fv + OFFSET) local offset = string.rep("\n", MAX - fv + OFFSET)
local bar = testkit.color.gray(remainder_to_block(v - fv) .. "\n" .. string.rep(BLOCK .. "\n", fv)) local bar = testkit.color.gray(remainder_to_block(v - fv) .. "\n" .. string.rep(BLOCK .. "\n", fv))
print(reset .. offset .. bar) print(reset .. offset .. bar .. "\n" .. v)
end) end)
local elapsed = 0 local T = 3
local elapsed = T/1.2
repeat local dt = step() repeat local dt = step()
vide.step(dt) vide.step(dt)
local T = 3
elapsed += dt elapsed += dt
while elapsed >= T do while elapsed >= T do
elapsed -= T elapsed -= T