## Spring-Damper

$$\renewcommand{\vec}{\mathbf{#1}}$$
This work is the result of part of a project I undertook in the early 1990s to devise software that would let me “paint a machine” onto my computer screen and then see it working. It was based on a system of particles connected with rods with various optional devices attached (rocket motors, wheels, parachutes, etc.), and was implemented on an Amiga 1200.

Imagine there are two particles $$\vec{p}_1$$ and $$\vec{p}_2$$ moving with velocities $$\vec{v}_1$$ and $$\vec{v}_2$$ respectively. They are connected by a spring of stiffness $$k$$ and natural length $$n$$, and a damper of resistance $$r$$.

We’re only dealing with 2 dimensions at the moment, so we convert the vectors to their Cartesian components thus:

$$\vec{p}_1=[p_{x_1},p_{y_1}]$$
$$\vec{p}_2=[p_{x_2},p_{y_2}]$$
$$\vec{v}_1=[v_{x_1},v_{y_1}]$$
$$\vec{v}_2=[v_{x_2},v_{y_2}]$$

$$p_x=p_{x_1}-p_{x_2}$$
$$p_y=p_{y_1}-p_{y_2}$$
$$v_x=v_{x_1}-v_{x_2}$$
$$v_y=v_{y_1}-v_{y_2}$$

## Spring Force

The force on the particles caused by the spring is equal to the difference in the spring’s natural length and its deformed length, divided by the natural length, all multiplied by the spring stiffness:

$$f_{spring}=k\frac{\sqrt{p_x^2+p_y^2}-n}{n}$$

(we have defined the the force to be positive when the spring is in tension, and negative when in compression)

## Damper Force

The force caused by the damper is a little more complex to calculate. It is equal to the rate of change of the length of the damper times the damper resistance.

First, we find the length of the damper, $$d$$, as a function of time, $$t$$:

$$d(t)=\sqrt{(p_x+v_xt)^2+(p_y+v_yt)^2}$$

This expands to:

$$d(t)=((p_x^2+p_y^2)+2(p_xv_x+p_yv_y)t+(v_x^2+v_y^2)t^2)^\frac{1}{2}$$

Next, we differentiate with respect to $$t$$ to find the rate of change:

$$d'(t)=\frac{1}{2}((p_x^2+p_y^2)+2(p_xv_x+p_yv_y)t+(v_x^2+v_y^2)t^2)^{-\frac{1}{2}}(2(p_xv_x+p_yv_y)+2(v_x^2+v_y^2)t)$$

Since we are only interested in the force at one instance in time we can evaluate at $$t=0$$:

$$d'(0)=\frac{1}{2}(p_x^2+p_y^2)^{-\frac{1}{2}}(2(p_xv_x+p_yv_y))$$

which simplifies to:

$$d'(0)=\frac{p_xv_x+p_yv_y}{\sqrt{p_x^2+p_y^2}}$$

multiply by the damper resistance to get the force:

$$f_{damper}=r\frac{p_xv_x+p_yv_y}{\sqrt{p_x^2+p_y^2}}$$

(we have defined the force to be positive when the damper is expanding, and negative when compressing)

## In 3 dimensions?

Ok, but what about in today’s miracle age of 3D, VR, jetpacks, and AR? Well, if you go through the above in 3 dimensions then you get the following:

$$f_{spring}=k\frac{\sqrt{p_x^2+p_y^2+p_z^2}-n}{n}$$

$$f_{damper}=r\frac{p_xv_x+p_yv_y+p_zv_z}{\sqrt{p_x^2+p_y^2+p_z^2}}$$

## In vector notation

Just in case you want to do the calculations in 4 dimensions (Marty), or more, then these are the equations in general vector notation:

$$\vec{p}=\vec{p_1}-\vec{p_2}$$
$$\vec{v}=\vec{v_1}-\vec{v_2}$$

$$f_{spring}=k\frac{|\vec{p}|-n}{n}$$

$$f_{damper}=r\frac{\vec{p}\cdot\vec{v}}{|\vec{p}|}$$

### Demo

Ok, there is no demo at the moment. I’ll get round to writing something in JavaScript or Unity “real soon now”