.:: Spring Mass Library In Python ::.
Ported form my C# Spring Mass Library
This program is a Python Spring Mass System library that I ported over from my C# version.
WARNING: for some reason the Python version connects every Mass together when you connect just one of them. I am still trying to figure out why it isn't working right. If you figure it out please help. Looks like Python and C# have some differences.
This graphic was generated by creating three connected masses. The left one has a downward velocity, the right one has an upward velocity, and the center mass is stationaty. When letting them run their course, they go into orbit around the center mass.
Testing collision detection.
METHODS AND VARIABLES OF MASS OBJECT
def Distance(self, mass1, mass2): #internal function for calculating distance between two Mass objects
def ConnectTo(self, mass2, k=1.0, MaxLengthFactor=2.0): #connect this mass to another one
def CollideWith(self, mass2, k=1.0): #turn on collision detection between this mass and another
def Move(self, dt=0.1,gravity=0.0): #translate the mass based on forces applied to it with Forces() and Collide()
def Forces(self): #calculate forces on the current mass based on its connections to other masses
def Collide(self): #calculate forces on the current mass based on its collision with other masses
Fixed = False #if True then the mass object does not move
x = 0.0 #x coordinate of mass in meters
y = 0.0 #y coordinate of mass in meters
vx = 0.0 #x velocity in m/s
vy = 0.0 #y velocity in m/s
mass = 10.0 #mass of the mass object in kilograms
diameter = 80.0 #diameter of mass object in meters