home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: Science
/
Science.zip
/
SPRING.ZIP
/
SPRING2.DOC
next >
Wrap
Text File
|
1992-04-30
|
4KB
|
133 lines
SPRING2.DOC
===========
This little program started as an investigation into 'damped oscillations'
such as those created by a pendulum moving through air, or a weight
attached to a spring. It soon became an exercise in modeless dialog boxes,
user painted controls and PM animation.
There are three basic components to the program:
Main Window:
------------
After starting the program, you will see the main window. I usually resize
this window so it's fairly small. What you see is a pale gray grid and
a two function plots, one in dark red and one in dark blue. The dark red
line plots the oscillatory motion along the X axis and the dark blue plots
the motion along the Y axis.
At first, both axes have identical parameters, so it just appears as one
blue line. The X axis of the grid is time in seconds, and the Y axis
is magnitude of oscillation. Each pale gray division shows one second.
Parms Window:
-------------
Pressing F6 (or clicking on the menu) brings up the Parameters dialog.
You use this dialog to control the variables in the oscillation function
for both the X and Y axes.
The 'Period' of oscillation controls the length of the oscillation period
in seconds.
'Mass' controls the mass of the object being oscillated.
'Damping' controls the effectiveness of the dampener. For instance, a body
oscillating in air has a lower damping factor than one oscillating in water.
'Phase' controls the beginning phase angle (in radians) for the oscillation.
The 'Copy' buttons simply duplicate the parameters up to X or down to Y.
The 'OK' button makes the changes permanent and closes the dialog.
The 'Cancel' button abandons all change and closes the dialog.
Animate Window:
---------------
Press F5 (or clicking on the menu) brings up the Animation dialog.
This dialog graphically animates the motion of the object in the X and Y
axes in real-time. The 'Weight' window contains a red box that represents
the object being oscillated.
The button controls in this window are similar to VCR-like controls. From
left to right they are defined as follows:
REWIND:
Resets the time counter to zero and stops the replay.
STOP:
Pauses the replay.
PLAY:
Starts (or unpauses) the animation at the current time.
FRAME:
Moves the animation forward one frame, to the next time increment.
CANCEL:
Closes the dialog.
EXAMPLE:
Start the program and press F6 for the Parms window. Modify the controls
so they are like this:
X Axis:
Period: 0.8000
Mass: 0.9600
Damping: 2.0000
Phase: 0.0000
Y Axis:
Period: 0.5000
Mass: 0.9600
Damping: 1.1200
Phase: 1.4451
Now press F5 and click on the PLAY button. This demonstrates the actual
motion of the object oscillating along the two axes.
CAVEATS:
--------
This program wasn't written for you, it was written for a friend studying
physics. However, you are welcome to use as you see fit.
Since I wrote the program in about a day and a half, there are a few bugs:
sometimes the animation dialog shows strange behavior. If it does, simply
cancel the dialog and bring it back up again.
Display update may vary. It works great on my 486-50, and it works OK on
my 386SX-16. Also, because the animation is based on snapshots of the
object position at a point in time, setting the 'period' to a very small
value will cause the animation to be confusing.
Resize the main window so it's fairly small. Parameter changes are
immediately reflected in the main window, so the smaller it is, the faster
it will update.
It's possible to click bring up more than one copy of each dialog box.
I just didn't put the code in to disable the menu options... If you do
this, unexpected results may occur!
This program was written in Zortech C++ and the OS/2 V1.2 toolkit, developed
on OS/2 1.3EE on a Gateway 486-50.
The formula for damped oscillations is:
-(b/2m)t
x = A e cos(wt + d)
Where:
A is the amplitude
b is the damping constant
m is the mass of the object
t is the time
w is the angular frequency (2pi / T)
d is the phase constant
-------------------------------------------------------------------------
That's all! Play with it if you like. Talk to me on CIS:71316,1603 or on
Pete Norloff's OS/2 Shareware BBS.
Steve Horne
CoralSoft, Inc.