Home / Episode 09 - Spring Force

* (right-click the video link and select "Save Link As..." or "Save Target As..." to download and view)

* Video (vpython09.avi, 76.6 MB, 19 min 12 sec) - March 30, 2006
view code


In this episode we model the behavior of a spring according to Hooke's Law and take a look at dragging and dropping objects in VPython.

Comments:

---------------------------------------------------------------------------
by Erik Thompson on 3.31.2006

A couple corrections to what I said in the video.

1. The Spring Force is greatest when the spring is fully stretched or compressed as it oscillates back and forth. I said it was greatest when it was at the relaxed position. The force is actually zero at that size.

2. In the drag and drop code, the line that moves the object being dragged is:
pick.pos.x += new_pos.x - drag_pos.x # offset for where the weight was clicked
for some reason I suggested it was:
drag_pos = new_pos # update drag position
That drag_pos is just a variable that we compare against the next time thru the loop so we know if the mouse has been dragged further and then we would need to update the objects position on the screen.

Also to run the program in slow motion so you can see the values for Force, Velocity, Acceleration, etc. just change the Rate(100) to a lower value such as Rate(20).
---------------------------------------------------------------------------

Add Your Comments (any code you enter is assumed to be in the public domain, no HTML tags):

Name
Comments
 

home