A Physics-Based General 3D Mass-Spring System
by Markus Gritsch ()
[ Download ]
[ Usage ]
[ Screenshots ]
[ Package Documentation ]
KineticsKit provides some classes written in Python to simulate the behaviour of a 3D
mass-spring-system. It can be used to investigate some basic kinetics, but I wrote it mostly for the fun of programming
it and playing with it.
Extract the ZIP archive into any folder which lies in your module-searchpath (e.g. the 'Lib/site-packages' folder).
Beside the KineticsKit classes, the archive also contains several instructive examples which show
how to use KineticsKit. Try them anyway - they make fun to play with. The picture of the lattice at the top of this page
is produced by an example included in the ZIP archive.
First a System has to be generated.
from KineticsKit import System, Mass, CylinderSpring
system = System(timestep=0.04)
The System has several attributes like gravity, viscosity and timestep which must be given in the constructor. Some of
them are mandatory (timestep), the rest of them are optional.
Next, Masses are generated and inserted into the System.
## generate some masses
mass1 = Mass(m=0.1, pos=(0.0, 0.0, 0.0))
mass2 = Mass(m=0.1, pos=(0.0, 0.5, 0.0))
## insert them into the system
Masses also have lots of attributes like m, pos, an indicator if it should be fixed at its initial location, its initial
velocity and the color. Most of them are implemented as keyword arguments and can thus be omitted if they are not
After this, the Masses can be connected with Springs. There are several types of Springs available which differ in their
visual appearance. Here we take a CylinderSpring.
## connect the masses with a spring
spring1 = CylinderSpring(m0=mass1, m1=mass2, k=1)
## insert the spring into the system
There is no restriction in making the connections, so one Mass can be connected with several others. A Spring needs to
know which two Masses it should connect, and its spring-constant. The rest of the constructor arguments are again
implemented as keyword arguments, but I recommend to take a look at them. They are useful to tense the Spring, specify a
damping value, select between different visual representations of the Spring, or give it a nicer color.
Finally the System has to be started and kept running with an infinite loop. The System also provides a convenience
function for this purpose.
## start the mainloop (convenience function)
For further details please have a look at the included example programs and the constructors of the
classes System, Mass and
Spring described in the package documentation.
Interaction with the System is possible with the mouse. A Mass is picked by clicking at it. It can be moved around and
the rest of the System responds to the movement. To release the Mass the mouse must be clicked again.
Zooming / rotating of the scene is also done with the mouse by holding the left / right mouse button down.
Please have a look at the examples. They are very useful to understand further details of KineticsKit.
The class reference and beautifully colored sourcecode can be found in the package
documentation. Make extensive use of it to reveal all the power of KineticsKit.
ActivityRecording / Leistungserfassung