collisions.py

Created by gianfranco-oddenino

Created on April 10, 2020

564 Bytes

The script solves a one-dimensional impact problem. The input data are the masses and the initial velocities of two objects. The final velocities, the initial and final total kinetic energies and the relative energy variation are calculated. The degree of elasticity of the impact can be selected by means of the return coefficient.


from math import *

print("Masses of objects")
m1=float(input("m1: "))
m2=float(input("m2: "))
print("Initial velocities")
v1i=float(input("v1: "))
v2i=float(input("v2: "))
print("Return coefficient")
cr=float(input("cr: "))

v1f=(m1*v1i+m2*v2i+cr*m2*(v2i-v1i))/(m1+m2);
v2f=(m1*v1i+m2*v2i+cr*m1*(v1i-v2i))/(m1+m2);
ki=0.5*m1*v1i*v1i+0.5*m2*v2i*v2i;
kf=0.5*m1*v1f*v1f+0.5*m2*v2f*v2f;
dk=(kf-ki)/ki;

print("Final velocities")
print("v1:", v1f)
print("v2:", v2f)
print("Kinetic energies")
print("Ki:", ki)
print("Kf:", kf)
print("(Kf-Ki)/Ki:", dk)