Solution to over damped harmonic spring

30 Views Asked by At

I'm trying to programmatically model a damped harmonic spring for use in mobile UI animations (physics isn't my background, please pardon any misconceptions).

Having derived the parameters for the general case equation, I can iteratively calculate values until I reach a suitable threshold, though because this is bound to "simple" C math trig and exp functions on the CPU, the 4000-some-odd steps can cause about 0.25 seconds on slow devices lag while it calculates. I'd like to speed this up using my platform's super-optimized vector and BLAS/LAPACK functions.

The requirement for doing this is precalculating the number of steps necessary to reach my threshold value.

In the underdamped case, where the roots of the characteristic function of the differential equation are non-real, I can use algebraic tricks to get my values:

$$x(t) = c_{1}e^{r_{1}}\cos(i_{1}t) + c_{2}e^{r_{2}}\sin(i_{2}t)$$

(Given $r_{1}$, $i_{1}$, $r_{2}$, and $i_{2}$ are the real and irrational components of my two roots, respectively.)

Knowing that $r_{1} = r_{2}$ and $i_{1} = -i_{2}$, I can simplify to:

$$x(t) = c_{1}e^{r_{1}}\cos(i_{1}t)$$

And get my desired value of $t$ for my threshold $a$:

$$t = \arccos(a / c_{1} / e^{r_{1}}) / i_{1}$$

When the roots are real, the equation is a lot simpler:

$$x(t) = c_{1}e^{r_{1}} + c_{2}e^{r_{2}}$$

But I don't have my trig functions floating around to help me solve it (even if I did, the irrational components being 0 would cause problems, of course).

Take the concrete example on pages 3-4 of this document (my bible during this process), since they at least solve cleanly:

$$x(t) = 1.5e^{-t} - 0.5e^{-3t}$$

I know how I would solve for $t$ to get my for when $x(t) = a$ on paper, by setting $x=e^{t}$, solving, and back substituting, but I don't have that luxury here.

How would I go about solving for my threshold value in this (supposedly) simplified case?