I am working on a two-dimensional collision with two moving objects. Its very simple. I have two spheres which have different geometry and mass. They colide at 45° angle. I need to calculate the velocity vectors of both spheres after the colision. I found a formula that I used on wikipedia and in this question: 2D Elastic Ball Collision Physics
The problem is that the resulting momentum is different than the starting one. The starting one is 35kgm/s and the end one is 33.75kgm/s. I looked at the proof for the formula, it uses the conservation of the total momentum, which probably means that the change of total momentum should be equal to 0. Mine is not.
Can anyone explain whats the issue or what am I doing wrong?
Thank you for your answers.
I tried it on different cases many times and I'm always a little off in the endind result.
My code:
import numpy as np
v_1 = np.array([3, 0]) #velocity of object 1
v_2 = np.array([0, 2]) #velocity of object 2
r_1 = 0.05 #m ; radius of sphere 1
r_2 = 0.1 #m ; radius of sphere 2
m_1 = 5 #kg ; mass of object 1
m_2 = 10 #kg ; mass of object 2
x_1 = np.array([-(r_1 + r_2)*np.cos(np.pi/4), 0]) #vector of position 1
x_2 = np.array([0, -(r_1 + r_2)*np.cos(np.pi/4)]) #vector of position 2
v_1_p = v_1 - 2*m_2/(m_1 + m_2)*((v_1 - v_2)@(x_1 - x_2))/(np.linalg.norm(x_2 -
x_1)**2)*(x_1 - x_2) #velocity after colision for object 1
v_2_p = v_2 - 2*m_1/(m_1 + m_2)*((v_2 - v_1)@(x_2 - x_1))/(np.linalg.norm(x_2 -
x_1)**2)*(x_2 - x_1) #velocity after colision for object 2
v_1_p_v = np.sqrt(np.sum(v_1_p**2)) #magnitude of velocity 1
v_2_p_v = np.sqrt(np.sum(v_2_p**2)) #magnitude of velocity 2
p_0 = np.sum(m_1*v_1 + m_2*v_2) #momentum before colision
# value: 35
p_1 = m_1*v_1_p_v + m_2*v_2_p_v #momentum after colision
# value: 33.74652441384409
I expected total momentum before the collision to be the same as after collision.
Problems:
np.sum(m_1*v_1 + m_2*v_2)
makes no mathematical sense because you are adding the components of the resultant momentum vector, which is not equal to the magnitude. Change it to m_1*v_1 + m_2*v_2
.
m_1*v_1_p_v + m_2*v_2_p_v
is incorrect because you cannot add vector magnitudes together to obtain the resultant vector's magnitude – ||v1|| + ||v2|| != ||v1 + v2||
. Change it to m_1*v_1_p + m_2*v_2_p
.
Beware of integer division in 2*m_2/(m_1 + m_2)
. Change it to (2.0*m_2)/(m_1 + m_2)
, and likewise for m_1
.