Really simple Python program to simulate inelastic collision

Click For Summary
SUMMARY

This discussion focuses on a Python program designed to simulate a completely inelastic collision between two objects. The user successfully calculates total kinetic energy and tracks the distance and velocity of both objects during the collision. The key insight provided clarifies that the heat released during the collision is determined by the difference between initial and final kinetic energy. The program utilizes a frame rate of 4000.0 and incorporates resistance to model the interaction between the two colliding objects.

PREREQUISITES
  • Understanding of Python programming (Python 3.x)
  • Knowledge of basic physics concepts, particularly inelastic collisions
  • Familiarity with kinetic energy calculations
  • Basic understanding of numerical simulation techniques
NEXT STEPS
  • Research how to implement friction in collision simulations
  • Learn about energy conservation principles in physics
  • Explore advanced numerical methods for simulating physical systems
  • Investigate Python libraries for physics simulations, such as Pygame or VPython
USEFUL FOR

Physics students, Python developers interested in simulations, and educators looking to demonstrate concepts of inelastic collisions and energy conservation.

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.
 

Similar threads

  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 1 ·
Replies
1
Views
5K
Replies
8
Views
2K
  • · Replies 4 ·
Replies
4
Views
8K
  • · Replies 2 ·
Replies
2
Views
17K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
Replies
2
Views
5K
Replies
10
Views
3K
Replies
10
Views
5K