Spring

The spring component is a scripted component that can be used to model springs with optional damping and plastic deformation. Springs act on dynamic joints, applying a force proportional to the difference between the joint’s current position and the resting position. They can act on either prismatic or revolute joints.

Properties

The spring component properties that are accessible through the inspector.

Stiffness

The stiffness coefficient for the spring. Increasing the stiffness will result in a greater force being applied to bring the joint back to the resting position. It may be necessary to reduce the timestep in order to simulate stiff springs without instability.

Damping

The damping coefficient for the spring. Increasing the dampings will cause the amplitude of oscillations to be reduced more quickly. Increasing the damping beyond the critical damping coefficient value will prevent oscillations.

Rest Offset

The resting offset is used to determine the resting position. The resting position is determined from the sum of the initial position of the joint and the resting offset. A resting offset of zero means that the initial position of the joint is equal to the resting offset.

Yield Displacement

The yield displacement is used to control plastic deformation of the spring. A yield displacement of zero will cause the spring to be perfectly elastic. A strictly positive yield displacement will cause the rest offset to change if the extension/compression of the spring exceeds the yield displacement.

Theory

There are two coefficients that affect the behavior of a spring: stiffness and damping. The total force applied by the spring is given by the sum of the forces due to stiffness and damping:

$$F=F_s+F_d$$

Stiffness

Stiffness is a measure of how much force is required to extend/compress the spring. A stiffness of zero means that the spring applies no force to bring the joint back to the resting position. A non-zero stiffness with zero damping will cause the joint to oscillate around the resting position. The force applied due to the stiffness is given by the following equation, where k is the spring constant and x is the difference between the current position and the resting position:

$$F_{s}=-kx$$

The period of the oscillation for a prismatic/linear spring is given by the following equation, where m is the mass of the body:

$$T=2\pi\sqrt{\frac{m}{k}}$$

Similarly, the period of oscillation for a revolute/tortional spring is givent by the following equation, where I is the moment of inertia of the body:

$$T=2\pi\sqrt{\frac{m}{I}}$$

If the stiffness is high, the spring may try to oscillate faster than the timestep. This causes the spring to become unstable. The maximum stiffness for stable oscillations can be calculated as follows:

$$k_{max}=\frac{m}{dt^2}$$
$$k_{max}=\frac{I}{dt^2}$$

Using the maximum stiffness will cause the spring to move the joint to the resting position in a single timestep. If your spring is unstable, you may need to either reduce the stiffness or reduce the timestep so as to increase the maximum stable stiffness.

Damping

Damping is a measure of how much energy is dissipated over a period of time. Positive damping values can be used to reduce or prevent oscillations. The force applied due to damping is given by the following equation, where c is the damping coefficient and v is the velocity of the joint:

$$F_{d}=-cv$$

The critical damping coefficient is the minimum coefficient value at which the spring no longer oscillates. The critical damping coefficient can be calculated using the following equations:

$$c_{c}=2\sqrt{km}$$
$$c_{c}=2\sqrt{kI}$$

Note that for revolute/tortional springs, the Parallel Axis Theorem must be applied to calculate the moment of inertia if the anchor point of the joint is not aligned with the center of mass of the body along the direction of the axis.

Plastic Deformation

Springs are perfectly elastic by default. This means that regardless of how much they are extended/compressed, the spring will eventually return the joint back to its resting position if no other forces are acting on the body. However, springs also support plastic deformation, where sufficient extension/compression will cause the spring to change its resting position. This can be used to model the folding of cardboard boxes, where sufficient deflection of the flaps should cause the flaps to remain folded.