# copied from KineticsKit to remove visual May 2003 jch import math from Point import Point # m = mass # v = velocity # F = force # fixed is whether the Physics system will move it. # pos[ition] class Mass: """Physical model and visual representation of a mass. """ #rho = 8900 # Cu rho = 23.8732414637845 # for backwards compatibility factor = 3. / (4 * math.pi * rho) def __init__(self, m, pos, fixed=0, v=[0,0,0]): """Construct a mass. """ self.m = float(m) self.pos = Point(pos) self.fixed = fixed self.v = Point(v) self.F = Point([0., 0., 0.]) def calcGravityForce(self, g): """Calculate the gravity force. """ # gforce = m * g self.F -= Point([0, self.m * g, 0]) def calcViscosityForce(self, viscosity): """Calculate the viscosity force. """ # Fviscosity = - v * viscosityFactor self.F -= self.v * viscosity def calcNewLocation(self, dt): """Calculate the new location of the mass. """ # F = m * a = m * dv / dt => dv = F * dt / m dv = self.F * dt / self.m self.v += dv # v = dx / dt => dx = v * dt self.pos += self.v * dt def clearForce(self): """Clear the Force. """ self.F = Point([0., 0., 0.]) def getPosition(self): return self.pos def setPosition(self,point): return self.pos.Assign(point)