This simulation demonstrates spring-mass oscillations and is currently being expanded.
A spring connection simulation models how a mass behaves when attached to a spring under the influence of gravity. The restoring force generated by the spring obeys Hook's Law, which states that the force exerted by the spring is proportional to the displacement from its rest length.
// Simplifies spring-mass system
let y = 1; // Position (m)
let vy = 0; // Velocity (m/s)
const k = 100; // Spring constant (N/m)
const L0 = 0.5; // Natural length of the spring (m)
const m = 10; // Mass (kg)
const g = 9.81; // Gravitational acceleration (m/s²)
const b = 1; // Damping coefficient (kg/s)
function draw(dt){
let Fspring = -k * (y - L0); // Spring force
let Fgravity = m * g; // Gravitational force
let Fdamping = -b * vy; // Damping force
let Fnet = Fspring + Fgravity + Fdamping; // Net force
let ay = Fnet / m; // Acceleration
vy += ay * dt; // Update velocity
y += vy * dt; // Update position
}| Parameter | Symbol | Description |
|---|---|---|
| Mass | m | Mass of the bob attached to the spring (kg). |
| Spring Constant | k | Stiffness of the spring, determining the restoring force (N/m). |
| Rest length | L₀ | Length of the spring when no forces are applied (equilibrium) (m). |
| Damping Coefficient | b | Resists motion, simulating energy loss due to friction or air resistance (kg/s). |