I've written a spring simulation for a UI in JavaScript, and everything is going great, users are able to throw UI elements all over the place and have them slide right where they need to go with a little wiggle.

However I'm trying to chain spring simulations together, and I'd like to know what time a spring will cross its equilibrium point so that I can ready the next animation in the chain to start at the right time and velocity.

How can I solve this formula for $t$ so I can know when the spring will cross a certain point? I'd like to know for all types of springs, but practically I'm only working with slightly underdamped ones. My current formula for finding an underdamped spring's displacement from its equilibrium is $$ f(t) = e^{-ct/2m} * (d_0 * cos(\frac{\sqrt{4mk - c^2}*t}{2m}) + \frac{2mv_0+cd_0}{\sqrt{4mk-c^2}} * sin(\frac{\sqrt{4mk - c^2}*t}{2m})) $$ where:

$m$: the mass of the springing object,

$k$: the stiffness of the spring, the spring constant,

$c$: the damping force,

$d_0$: the springing object's initial distance from its equilibrium at $time = 0$ ,

$v_0$: the springing object's velocity once the user lets go of it at $time = 0$,

and $t$ for time.

Can I solve this mess for $t$ rather than $f(t)$?

  • 1
    $\begingroup$ You will need to solve it numerically, I don't think it has an analytic solution $\endgroup$
    – user65081
    Aug 18, 2021 at 23:49
  • $\begingroup$ You are missing a parenthesis around the sine and cosine terms to multiply with the exponential. The general solution should be of the form $$x= \exp(-\beta t) \left( A \sin (\omega t) + B \cos( \omega t) \right) $$ $\endgroup$ Aug 19, 2021 at 1:09
  • $\begingroup$ @JohnAlexiou It was right there in the code too... thanks, I missed that, edited to reflect $\endgroup$ Aug 19, 2021 at 2:51

1 Answer 1


There is an analytical solution, if you bring the equation to the form $$ x = R \exp(-\zeta \theta) \cos \left(\theta \sqrt{1-\zeta^2}+\psi \right) $$

The solution for $x=0$ is

$$ \theta = \frac{ \frac{\pi}{2} ( 2 i -1) - \psi }{\sqrt{1-\zeta^2}} $$

where $i=1,2,3 \ldots \infty$. The time and angle are related as $\theta = \omega_n t$, with $\omega_n^2 = \frac{k}{m}$ and damping ratio $\zeta = \frac{c}{2 m \omega_n}$.

The amplitude is $R = \sqrt{A^2+B^2}$ and phase $\psi =-\arctan(A/B)$ where $A$ is the coefficient of $\sin()$ and $B$ the coefficient of $\cos()$.

  • $\begingroup$ Thank you for an awesome answer. If it helps anybody here's a graph with both plotted & variable values. Thanks again, you saved me a ton of time & I hope to actually understand what you did some day. $\endgroup$ Aug 19, 2021 at 3:34
  • $\begingroup$ @NorrisDuncan - I am glad it worked out. It seems you are doing similar things I did in the 80's with BASIC on the BBC Micro. I managed to make a career out of it, so cheers to you. $\endgroup$ Aug 19, 2021 at 12:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.