Loading...
Logo
Processing Forum

Simulation of a spring?

in General Discussion  •  Other  •  1 year ago  
Hello :)

I am working on a project which is targeted to simulate laboratory physics and chemistry experiments for class IX and X. It will be an Online Lab where the behavior of apparatus will be simulated, and the student will be able to conduct the experiment online.

One such experiment requires the simulation of a mechanical spring hung from a roof. (verification of hooke's law). The student is supposed to add different weights and measure the stretch of the spring.

I am new to processing, and I can't think of how to simulate a spring. Any help in this regard will be great help. I just want to get started and the rest I will be able to follow on my own.

Please help me.

Replies(5)

I can think of two ways to approach this:
• you create a blob and have it act under two forces - gravity and the spring
• you know that the blob on a spring moves using simple harmonic motion, so you make the blob describe SHM
I'd go with the former.

Things to consider then:
• in animation we often do movement by adding the object's velocity to its position:
Copy code
  1. blobx += velx;
  2. bloby += vely;

• and to add gravity we add that acceleration to the y velocity:
Copy code
  1. vely += gravity;

• at the same time, you need to deal with the spring. One way to do this is like this:
Copy code
  1. velx += (targetx - blobx) * springAmount;
  2. vely += (targety - bloby) * springAmount;
and make the springing decay a bit by applying some friction:
Copy code
  1. velx *= friction;
  2. vely *= friction;
with springAmount = 0.1 and friction = 0.95, say

This is described really well in Making things move by Keith Peters.



This is described really well in Making things move by Keith Peters.

Couldn't agree more, or recommend this book highly enough - Even if you're not an AS2/3 developer the principles it teaches for animating 'physics' are clearly, and brilliantly explained. You can get the AS2 edition for about £1 used on Amazon and it's a breeze getting the code running in Processing when you understand them.

Cheers

Dave

Calx | http://calx.co.uk
There are also some nice physics-libraries. For eaxample:
http://murderandcreate.com/physics/
http://www.shiffman.net/teaching/nature/toxiclibs/

Might be worth a look.

Using anything else but the proper simple harmonic motion would fail the purpose, imo. If I was a student and were not able to trace visualized motion back to he proper physical formula, I would instantly loose respect for the creater and eventually the teacher. After all .. I don't need to know what a blob on a spring looks like .. I already know that. Predicting where it will be in a minute would be the whole idea.
ShivaChat needs to calculate the position of a blob, from a set of start-conditions or involve an impulse on a system at rest. It shouldn't be rocket science for a physics teacher.

If you code all the physics, then the blob moves in SHM!