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?

You will find a demo of this here.

We assume that we have no friction between the balls, so all the forces acting must be normal forces, and thus the collisions cannot cause any rotation of the balls. Let us start by assuming that one of the balls is initially at rest. We 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 for 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 in 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 that it would 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,

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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
// This function moves the balls // and checks if a particle will bounce on a // wall. If so it will change the direction // of the perpendicular component of the // motion. If the particle moves in the vertical // direction the velocity will change due to // gravity. move: function () { for (let i = 0; i < n; i++) { let ball = this.ball[i]; ball.x += ball.vx * dt; ball.y += (ball.vy + g / 2) * dt; if (ball.y < this.radius) { if (ball.vy < 0) ball.vy *= -1; ball.y += (ball.vy - g / 2) * dt; } else if (ball.y > canvas.height - this.radius) { if (ball.vy > 0) ball.vy *= -1; ball.y += (ball.vy - g / 2) * dt; } else ball.vy += g * dt; if (ball.x < this.radius) { if (ball.vx < 0) ball.vx *= -1; ball.x += ball.vx * dt; } else if (ball.x > canvas.width - this.radius) { if (ball.vx > 0) ball.vx *= -1; ball.x += ball.vx * dt; } } }, // This is to check if particle i and j // has collided. The horizontal distance between // the balls is checked to see if a collision // is possible, if so, then the actual distance is // checked. If a collision is still // possible then it is checked if the balls are moving // toward each other => collision, or not. // Then the calculations to simulate // a totally elastic collision is done. // For more info, look at // https://properhoc.com/physics/themodynamics/colliding-nonrotating-balls-in-2d/ collision: function (i, j) { let ballI = this.ball[i]; let ballJ = this.ball[j]; let dx = ballI.x - ballJ.x; if (Math.abs(dx) < this.diameter) { let dy = ballI.y - ballJ.y; let d2 = dx ** 2 + dy ** 2; if (d2 < this.diameter2) { let dvx = (ballJ.vx - ballI.vx) * dt; let dvy = (ballJ.vy - ballI.vy) * dt; let dvs = dx * dvx + dy * dvy; if (dvs > 0) { dvs = dvs / d2; dvx = dvs * dx; dvy = dvs * dy; ballI.vx += dvx; ballI.vy += dvy; ballJ.vx -= dvx; ballJ.vy -= dvy; } } } }, |

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.

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 proceed with the calculations described above.

Previous page : A simulation of an Atmosphere

Next page : Grouping the particlesLast modified: