Python Really simple Python program to simulate inelastic collision

AI Thread Summary
The discussion centers on a Python program simulating a completely inelastic collision between two objects. The user is seeking clarification on calculating the "heat released" during the collision. The program calculates total kinetic energy before the collision and tracks the distance and velocity of both objects over time, factoring in resistance. The key point is that the heat released can be determined by the difference between initial and final kinetic energy, which is essential for understanding energy conservation in the system. The user expresses a lingering confusion about friction, indicating a potential area for further inquiry.
remote
Messages
8
Reaction score
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
 
Technology news on Phys.org
Total energy, the sum of kinetic and thermal energy, is conserved. The released heat is just the difference between initial and final kinetic energy.
 
Thanks. That gave me the hint I needed to fix the program.

I'm still a bit confused about how friction works, but I think I can ask about that in another thread.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...
Back
Top