## Spring

In CindyLab a spring is very similar to a Rubber Band. A spring is constructed by a press/drag/release sequence as in Add a Line mode. If the endpoints of the spring segment are not already present in the drawing, free mass-objects will be added. A spring causes forces to act on its two endpoints. Unlike rubber bands, springs have a resting length at which the force is zero. If the distance between the two endpoints is smaller than the resting length, the force will be repulsive. If it is larger than the resting length, the force will be attractive. The force is calculated by the formula

force = springconstant ∗ |length – restlength|

Here |x| denotes the absolute value of x, springconstant is a characteristic constant of the spring that can be adjusted in the inspector, restlength is the resting length of the spring, and length is the distance between the two points. Springs are very powerful objects that admit many variations via the inspector. So we will first have a look at the inspector before we discuss the various possibilities for defining a spring.

### Inspecting Springs

The spring inspector comes with a great variety of possibilities for modification. We will discuss these modifications one by one.

The spring inspector
``

Spring Strength
The spring strength slider helps in adjusting the value of springconstant. No matter what kind of interaction is modeled by the spring, the springconstant acts as a factor by which the final force is multiplied. Thus setting this slider to a value of zero is equivalent to removing the spring from the configuration.

``

Spring Type
In CindyLab all interactions between pairs of points are internally modeled as springs. Thus it is simple to switch between the different types of interaction. This can be done by choosing the springtype in the inspector. Currently, there are four different types of interaction implemented. Each of them comes with a specific behavior (and formula) for the spring.

``

The four types are defined as follows:
rubber band: For this spring type it is assumed that the spring has a resting length of zero. Thus the force between the two masses is always attractive. Its absolute value is calculated by the formula

force = springconstant ∗ length.

This type is the default spring type when a Rubber Band is added.
spring: For this spring type it is assumed that the spring has a positive resting length. Thus the force between the two masses will be attractive if the two masses are farther apart than the resting length. It will be repulsive if they are closer than the resting length. The absolute value of the force is calculated by the formula

force = springconstant ∗ (length – restlength)

This type is the default type when a spring is added.
Newton force: This spring type models the gravitational attraction between two bodies. This force depends on the masses of the bodies and the distance between them. It is always attractive. The absolute value of the force is calculated by the formula

force = springconstant ∗ mass1 ∗ mass2 / dist²

Coulomb force: This spring type models the interaction between electrically charged particles. This force depends on the charges of the particles and on the distance between them. It is attractive if the charges have opposite signs and repulsive otherwise. The absolute value of the force is calculated by the formula

force = springconstant ∗ charge1 ∗ charge2 / dist²

This type is the default spring type when a Coulomb Force is added.
Restlength
The two items Restlength from picture and Length at rest are relevant only if the spring has a resting length.

``

If Restlength from picture is checked, then the resting length of the spring is defined to be the length of the spring in the drawing when the simulation is started. Thus in this case, a single spring with two mass-objects not otherwise connected at the endpoints exerts no force on the masses.
If this box is not checked, the spring's resting length will be defined by the Length at rest value in the inspector.
Spring Actuation
The two items Amplitude and Phase will be relevant only if the spring has a resting length. In this case, CindyLab provides the possibility to vary the resting length periodically in time. The resting length is then modulated by a sine function, causing it to become periodically longer and shorter.

``

The amplitude of the resting length variation can be adjusted by the Amplitude slider. The phase of the vibration with respect to the other springs can be adjusted by the Phase slider. The speed of the oscillation is globally adjusted in the Environment inspector.

### Examples

Due to their programmatic flexibility, springs can be used in many different circumstances. Here we will present just a few examples and pictures that exemplify the use of springs.
A Bridge
The first example shows a network of springs that simulates the behavior of a bridge. All springs in this example are used with the default physical setup. However, the appearance of the springs has been slightly altered. Usually, springs are rendered as wiggly objects. This feature can be turned off by the render button in the inspector. Furthermore, CindyScript code was added to change the color of the springs according to their interior tension.

A bridge constructed with springs
``

Double Pendulum
The next example shows the chaotic movement of a double pendulum. Here two springs are connected and one endpoint is fixed to the ground plane. The springconstant is set to a relatively high value so that the springs behave nearly like rigid rods. The picture shows the movement of this double pendulum under the influence of gravity.

The chaotic motion of a double pendulum
``

Two-Body Movement
The next pictures show two mass particles with initial velocities and their behavior under gravitational forces. For this example, the type of the spring was set to Newton's law. The two mass particles simulate a system of two stars that orbit each other.

Two instances of two-body motion
``

### Springs and CindyScript

Like any CindyLab object, a spring provides several fields that can be read and very often set by CindyScript. The following list shows the accessible fields for springs:

- l: current length of the spring (real number, read only)
- lrest: resting length of the spring (real number, read and set)
- ldiff: current length difference to the resting length (real number, read only)
- potential: the potential energy of the spring (real number, read only)
- pe: the potential energy of the spring (real number, read only)
- strength: the spring constant (real number, read and set)
- amplitude: the amplitude of actuation (real number, read and set)
- phase: the phase of actuation (real number, read and set)
- simulate: turn on/off simulation for this spring (Boolean, set and read)

### See also

- Add a Line
- Environment
- Rubber Band
- Coulomb Force

Page last modified on Friday 02 of December, 2005 [10:49:42 UTC].
The original document is available at http://doc.cinderella.de/tiki-index.php?page=Spring