- #1
remote
- 8
- 1
I'm trying to write this Python program that simulates a completely inelastic collision between two objects. The program seems to work for the most part, but I'm completely lost on the "heat released" part at the end. I have no idea if I'm calculating this right, or if I'm completely wrong. Can anyone give me some insight?
Code:
frameRate = 4000.0
mass = 1.0
velocity = 1.0
distance = 0.0
mass2 = 1.0
velocity2 = 0.0
distance2 = 0.0
maxTime = 50
resistance = 1.0
time = 0.0
print "total kinetic energy: ", .5 * mass * velocity * velocity + .5 * mass2 * velocity2 * velocity2
#now we collide two objects, and see how long it takes them to reach the same speed
while True:
distance += velocity / frameRate
distance2 += velocity2 / frameRate
velocity2 -= (resistance * (velocity2 - velocity)/ mass2) / frameRate
velocity -= (resistance * (velocity - velocity2) / mass) / frameRate
time += 1 / frameRate
if time > maxTime:
break
if velocity <= velocity2 + .01:
break
print "colliding\n\n"
print "time elapsed: ", time
print "object 1 distance traveled: ", distance
print "object 2 distance traveled: ", distance2
print "object 1 velocity: ", velocity
print "object 2 velocity: ", velocity2
print "heat released: ", (distance - distance2) * resistance