Simulation of Elastic Collisions

  • #36
haruspex said:
  • calculate the direction of that line
  • resolve the velocities into coordinates parallel to and normal to that line
  • convert velocities along the line into being relative to one of the discs
  • compute the new velocities along that line
  • convert back to the lab frame
  • take the velocities normal to the line of centres to be unchanged
  • resolve the velocities back into your standard xy coordinates
This is what I did except that I did not use relative velocity.
Code:
function update_velocities!(vx1, vy1, vx2, vy2, x1, y1, x2, y2, r1, r2, m1, m2)
    # Relative position
    Δx = x2 - x1
    Δy = y2 - y1
    distance = sqrt(Δx^2 + Δy^2)
    
    # Normal vector (unit vector from particle 1 to 2)
    nx = Δx / distance
    ny = Δy / distance

    # Tangent vector (perpendicular to the normal vector)
    tx = -ny
    ty = nx

    # Dot products with normal vector
    vn1 = vx1 * nx + vy1 * ny
    vn2 = vx2 * nx + vy2 * ny

    # Dot products with tangent vector (remain unchanged)
    vt1 = vx1 * tx + vy1 * ty
    vt2 = vx2 * tx + vy2 * ty

    # Update normal components based on elastic collision principles
    new_vn1 = (vn1 * (m1 - m2) + 2 * m2 * vn2) / (m1 + m2)
    new_vn2 = (vn2 * (m2 - m1) + 2 * m1 * vn1) / (m1 + m2)

    # Update velocities
    vx1_new = tx * vt1 + nx * new_vn1
    vy1_new = ty * vt1 + ny * new_vn1
    vx2_new = tx * vt2 + nx * new_vn2
    vy2_new = ty * vt2 + ny * new_vn2

    return vx1_new, vy1_new, vx2_new, vy2_new
end

I wanted to consider a situation where the velocity changes in both directions, even perpendicular to the line connecting the centers of mass of two objects.
1736117371407.png

But as I mentioned in post #34, I regret it, and it's a waste of time in my opinion.

haruspex said:
You also need to watch out for overflow when doing divisions or using the tan function. E.g. when coding the use of a division you will need to think about the physical meaning of the denominator being extremely small.
I can't see how it might happen in my code.
 
Last edited:
Physics news on Phys.org
  • #37
MatinSAR said:
This is what I did except that I did not use relative velocity.
Your code looks good.
MatinSAR said:
I wanted to consider a situation where the velocity changes in both directions, even perpendicular to the line connecting the centers of mass of two objects.
View attachment 355380
There is no such situation. On what basis would you decide those velocity changes?
I believe the diagram you posted is merely a simplified version, not showing the line of centres at impact (which must have been parallel to ##v_{2,f}##).
See the diagrams at https://www.physicsforums.com/threads/how-does-elastic-collision-angle-relate-to-mass-ratios.983227/.
 
  • Like
Likes MatinSAR
  • #38
Output of my work as a GIF: (this is the 1st version)

particle_collision_simulation_optimized.gif
 
Last edited:
  • Like
Likes Steve4Physics, SammyS, kuruman and 2 others
  • #39
haruspex said:
On what basis would you decide those velocity changes?
I believed that, in general, the force exerted on particle 2 by particle 1 is not aligned with the line connecting their centers. But it is, yes?
haruspex said:
There is no such situation. On what basis would you decide those velocity changes?
I believe the diagram you posted is merely a simplified version, not showing the line of centres at impact (which must have been parallel to ##v_{2,f}##).
See the diagrams at https://www.physicsforums.com/threads/how-does-elastic-collision-angle-relate-to-mass-ratios.983227/.
It seems I misunderstood this concept. I'll need to go over the chapter on collisions again, more carefully.
 
  • #40
MatinSAR said:
I believed that, in general, the force exerted on particle 2 by particle 1 is not aligned with the line connecting their centers. But it is, yes?
In the idealisation of uniform spheres, no friction, it will be aligned with the line of centres.
 
  • Like
Likes MatinSAR
  • #41
  • Like
Likes erobz and MatinSAR
  • #42
haruspex said:
In the idealisation of uniform spheres, no friction, it will be aligned with the line of centres.
I understand.
haruspex said:
Excellent!
Thank you for your help. It has been very helpful.
 

Similar threads

Replies
6
Views
1K
Replies
16
Views
3K
Replies
13
Views
661
Replies
18
Views
1K
Replies
22
Views
3K
Replies
47
Views
2K
Back
Top