Previous page : A simulation of an Atmosphere

Next page : Grouping the particles

In 1D a totally elastic collision between two balls is rather easy to figure out, but how about in 2D?

We assume that we have no friction between the balls, so that all the forces acting must be normal forces, and thus that the collisions cannot cause any rotation of the balls. Let us start with assuming that one of the balls is initially at rest. Wi can shift our perspective, and our frame of reference, by subtracting the x-and y- components of the velocity of the second particle from both. In that way the second will be at rest in the new frame of reference. We have

Or, written as vectors,

The forces acting on the two particles as they collide will be along the axis connecting their midpoints of the reasons mentioned above.

The acceleration, and thus the changes in velocity must hence be parallel to the line connecting the two midpoints.

We may now split *Δ v* in two components, one parallel to the forces, and one perpendicular, as in the figure. The

*Δ*will now be the change of the velocity of the second particle, and since we must conserve momentum, we must change the velocity of the second particle by the same amount, but in the opposite direction. It will thus, in our frame of reference, end up with the velocity

**v**_{s}The second particle was initially at rest, so it will end up with the velocity *Δ***v**_{s}_{.}

We can here see that the kinetic energy is conserved too, since we have that the end velocities are perpendicular to each other, so by Pythagoras’s we get

Ok, so we need to find *Δ***v*** _{s}*. This is basically the projection of

*Δ*

**v**onto the line connecting the two centres of the particles. We can here use a lot of algebra, or, if we know the scalar product we have that

where *θ* is the angle between **d** and *Δ***v**. What we are looking for is

where

This will give us the magnitude. What we also know is that *Δ***v*** _{f}* is parallel to

**d**. This will enable us to find the

*x*– and

*y*-components of

*Δ*by using the similar triangle made by

**v**_{f}*d*,

*Δd*and

_{x}*Δd*.

_{y}By similarity we get

or

Combining this with the equation

we get,

These values are thus the changes in velocities for the two particles. We add these to the components of the initial velocity of particle 2 and subtract it from the initial velocity of particle 1 – and we now have the velocities of the particles after the collision.

Let us look at a bit of JavaScript that uses this.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
// This calculates the changes in the direction // of motion of two circular particles of // equal size and mass. The collision // is totally elastic - and there // are no friction involved. // The particle data is stored in an array // where each entry is of the form // {x:value, y:value, vx:value, vy:value}. // This is free to use - but I'm happy if you add a link to // this page in your code. function collision(i, j) { // First we find the components of d. let dy = particles[i].y - particles[j].y; let dx = particles[i].x - particles[j].x; // Then we calculate d^2. let d2 = dx ** 2 + dy ** 2; // If d^2<the diameter och the particles^2 then we might // have a collision. if (d2 < diameter2) { // Then we calculate the components of difference // in velocities. let dvx = particles[j].vx - particles[i].vx; let dvy = particles[j].vy - particles[i].vy; // Then we calculate the dot product... let dvs = dx * dvx + dy * dvy; // ... and if this is positive the particles are // colliding. if (dvs > 0) { dvs = dvs / d2; dvx = dvs * dx; dvy = dvs * dy; particles[i].vx += dvx; particles[i].vy += dvy; particles[j].vx -= dvx; particles[j].vy -= dvy; } } } |

Here we have used the result of the dot products in two ways. The first is to use it to determine if the particles are moving toward each other, so that will have a collision, or away from each other. If the vector *Δ v_{s}* is pointing in the opposite direction from the vector from particle 1 to particle 2 then the dot-product is negative, and the particles are moving away from each other. If the dot-product is positive, we go on with the calculations as described above.

Previous page : A simulation of an Atmosphere

Next page : Grouping the particlesLast modified: