website/content/blog/1d-collisions/index.md

210 lines
8.4 KiB
Markdown
Raw Normal View History

2024-04-30 11:10:10 +03:00
# Elastic Collisions Simulation
2024-04-30 10:37:01 +03:00
## 1. Introduction
2024-04-30 10:55:29 +03:00
Recently, the recommendation system of a video hosting site suggested me to watch a video of several cubes colliding. It appeared to be an intriguing concept. After viewing the video, I was inspired to create a simulation of that process and explain its underlying principles.
2024-04-30 10:37:01 +03:00
2024-04-29 21:22:06 +03:00
## 2. Relevance
There are numerous reasons why this project is relevant, as well as a wide range of potential applications. The following will outline the primary reasons and applications:
- It can be used in the educational process. For instance, it can be used to illustrate some principles of mechanics to students and to visualize some physics problems.
2024-04-30 11:00:23 +03:00
- It can be used to simulate some physical experiments. For instance, it can be used to simulate the one described in _G. A. Galperin's work_.[^1]
2024-04-29 21:22:06 +03:00
2024-04-29 22:01:58 +03:00
- It can be used as a basis for future projects.
2024-04-29 14:54:26 +03:00
2024-04-29 15:41:57 +03:00
## 3. The consequences of collisions
2024-04-29 14:54:26 +03:00
2024-04-30 12:01:34 +03:00
Firstly, it is essential to comprehend how the velocity of the body after collision is calculated. We will solve the problem in the elastic collision model (one-dimensional Newtonian).
2024-04-29 14:56:14 +03:00
2024-04-30 12:04:10 +03:00
### 3.1 Body-Body
2024-04-29 14:56:14 +03:00
2024-04-30 11:43:41 +03:00
Consider two bodies, designated as bodies `1` and `2`, with respective masses $m_1$ and $m_2$. Before the collision, the velocities of bodies 1 and 2 are $v_1$ and $v_2$, respectively. After the collision, the velocities of bodies 1 and 2 are $v_1'$ and $v_2'$, respectively.
2024-04-29 15:10:31 +03:00
2024-04-30 11:43:41 +03:00
In any collision, momentum is conserved. A collision between to bodies is said to be elastic if it involves no change in their internal state. Accordingly, when the law of conservation of energy is applied to such a collision, the internal energy of the bodies may be neglected.[^2]
2024-04-29 14:54:26 +03:00
2024-04-29 15:25:58 +03:00
The conservation of momentum before and after the collision is expressed by the following equation:
2024-04-29 14:54:26 +03:00
2024-04-29 13:29:41 +03:00
$$
m_{1}\vec{v}_{1} + m_{2}\vec{v}_{2} = m_{1}\vec{v'}_{1} + m_{2}\vec{v'}_{2}
$$
2024-04-29 15:25:58 +03:00
And the conservation of the total kinetic energy before and after the collision is expressed by the following equation:
2024-04-29 13:29:41 +03:00
$$
\frac{m_{1}{v_{1}}^2}{2} + \frac{m_{2}{v_{2}}^2}{2} = \frac{m_{1}{v'_{1}}^2}{2} + \frac{m_{2}{v'_{2}}^2}{2}
$$
2024-04-29 15:37:28 +03:00
If we consider the law of conservation of momentum in projection on the X-axis, we can transform the previous equations into the following system:
2024-04-29 15:25:58 +03:00
2024-04-29 13:29:41 +03:00
$$
\begin{cases}
m_{1}({v_{1}} - {v'_{1}}) = m_{2}({v'_{2}} - {v_{2}}) \\
m_{1}({v_{1}}^2 - {v'_{1}}^2) = m_{2}({v'_{2}}^2 - {v_{2}}^2)
\end{cases}
$$
2024-04-29 15:25:58 +03:00
The division of each side of the top equation by each side of the bottom equation yields:
2024-04-29 13:29:41 +03:00
$$
\frac{v_{1} - v'_{1}}{{v_{1}^2} - {v'_{1}}^2} = \frac{v'_{2} - v_{2}}{{{v'_{2}}^2} - {v_{2}}^2}
$$
2024-04-29 15:25:58 +03:00
The preceding equation may be transformed using the difference of two squares formula to obtain the following:
2024-04-29 13:29:41 +03:00
$$
\frac{v_{1} - v'_{1}}{(v_1 + v'_1)(v_1 - v'_1)} = \frac{v'_{2} - v_{2}}{(v'_2 - v_2)(v'_2 + v_2)}
$$
2024-04-29 15:25:58 +03:00
This expression can be transformed as follows:
2024-04-29 13:29:41 +03:00
$$
\frac{1}{v_1 + v'_1} = \frac{1}{v'_2 + v_2}
$$
2024-04-29 15:25:58 +03:00
From this expression follows:
2024-04-29 13:29:41 +03:00
$$
v_1 + v'_1 = v'_2 + v_2
$$
2024-04-29 15:25:58 +03:00
From this equation, the following system can be derived:
2024-04-29 13:29:41 +03:00
$$
\begin{cases}
v'_1 = v_2 + v'_2 - v_1 \\
2024-04-29 13:09:54 +03:00
v'_2 = v_1 + v'_1 - v_2
2024-04-29 13:29:41 +03:00
\end{cases}
$$
2024-04-29 13:09:54 +03:00
2024-04-29 15:25:58 +03:00
The law of conservation of momentum then yields the following:
2024-04-29 13:29:41 +03:00
$$
\begin{cases}
m_1v_1 + m_2v_2 = m_1{v'}_1 + m_2(v_1 + {v'}_1 - v_2) \\
2024-04-29 13:09:54 +03:00
m_1v_1 + m_2v_2 = m_1(v_2 + v'_2 - v_1) + m_2v'_2
2024-04-29 13:29:41 +03:00
\end{cases}
$$
2024-04-29 13:09:54 +03:00
2024-04-30 11:43:41 +03:00
From this, we can derive the velocity of the bodies following the collision as follows:
2024-04-29 15:25:58 +03:00
2024-04-29 13:29:41 +03:00
$$
\begin{cases}
v'_1 = \frac{2m_2v_2 + v_1(m_1-m_2)}{m_1+m_2} \\
2024-04-29 13:09:54 +03:00
v'_2 = \frac{2m_1v_1 + v_2(m_2-m_1)}{m_1+m_2}
2024-04-29 13:29:41 +03:00
\end{cases}
$$
2024-04-29 16:00:34 +03:00
2024-04-30 12:04:10 +03:00
### 3.2 Body-Wall
2024-04-29 16:00:34 +03:00
2024-04-30 12:04:49 +03:00
Consider the body and the wall with respective masses $m$ and $m_w \rightarrow \infty$. Before the collision, the velocities of the body and the wall are $v$ and $v_w = 0$, respectively. After the collision, the velocities of the body and the wall are $v'$ and $v_w'$, respectively.
2024-04-29 16:00:34 +03:00
In order to proceed, we will utilize the formulas derived in section **3.1**.
2024-04-30 12:01:34 +03:00
The velocity of the body will take the following form:
2024-04-29 16:00:34 +03:00
$$
v' = \lim\limits_{m_w \to \infty} \frac{2m_wv_w + v(m-m_w)}{m+m_w} = \lim\limits_{m_w \to \infty} \frac{v(m-m_w)}{m+m_w} = -v
$$
The velocity of the wall will take the following form:
$$
2024-04-29 16:04:52 +03:00
v_w' = \lim\limits_{m_w \to \infty} \frac{2mv + v_w(m_w-m)}{m+m_w} = \lim\limits_{m_w \to \infty} \frac{2mv}{m+m_w} = 0
2024-04-29 16:00:34 +03:00
$$
2024-04-30 12:01:34 +03:00
This leads to the conclusion that the wall will not change its position, but the body will change its velocity value to the opposite.
2024-04-29 21:22:06 +03:00
2024-04-30 15:02:50 +03:00
## 4. Technical implementation
### 4.1 Simulation
To create the simulation (animation), it was determined that `Processing` technology, specifically `p5.js`[^3], would be the most suitable.
We will assume that the bodies have the form of two squares of different sizes and colors. The smaller body will be placed to the left of the larger body.
2024-04-30 15:07:22 +03:00
The following variables should also be defined:
- $v_1, v_2$ - Velocities of the bodies (respectively).
- $w_1, w_2$ - Widths of the bodies (respectively).
- $m_1, m_2$ - Masses of the bodies (respectively).
- $x_1, x_2$ - Current coordinates of the bodies (respectively).
- $c_1, c_2$ - Constraints of the bodies coordinates (respectively).
2024-04-30 15:02:50 +03:00
The initial step was to meticulously program the model of the bodies:
1. For visual convenience, the width of the first body will be $w_1 = 50$ and the second's will be $w_2 = 100$.
2. Furthermore, for the sake of visual clarity, the coordinates for the bodies will be as follows: $x_1 = 100$, $x_2 = 300$.
2024-04-30 15:07:22 +03:00
3. The physical constraint (`p5.constrain`) of the first body's coordinate will be $c_1 = 0$, of the second body's coordinate $c_2 = 0 + w_1 = 50$
2024-04-30 15:02:50 +03:00
4. The initial velocity of the bodies and their mass are set by the user, so for the time being, we will leave them as constants.
Another step is to describe the algorithm of their movement:
1. If the first smaller body makes contact with the wall ($x_1 <= 0$), adjust its velocity in accordance with the formula described in section **3.2**.
2. If the bodies collide with each other, then set each of them velocity according to the formulas given in **3.1**.
The next step is to determine the best method for animating the object and moving it with a specified velocity.
To enhance the smoothness of animations and reduce load times, the following steps were taken:
- It was decided to create a loop in the `move` function (`p5.js`) that will perform a given number of operations ($10^6$).
- The user-specified initial velocity will also be br divided by $10^6$.
2024-04-30 15:16:47 +03:00
### 4.2 User Options
For the convenience of users, the velocity and mass of each body can be set according to the user's preferences.
To streamline the user experience and avoid overwhelming the page of the simulator with unnecessary buttons and technical complexities, it was decided to use apply new settings and restart an animation when user reloads the browser page.
So, once the user has entered data into the designated fields, it is automatically saved to the localStorage. [^4]
2024-04-30 15:27:40 +03:00
## 5. Usage
### 5.1 Common problems
We recommend avoiding setting particularly large values for variables, because:
- Despite the use of optimization tools, there may be instances where the page will use a significant amount of your device's resources.
- Large values may result in animation crashes and premature stopping of counting.
### 5.2 Experience
2024-04-30 15:31:46 +03:00
The interface of the simulation UI is as follows:
2024-04-30 15:27:40 +03:00
![img](https://cdn.arbuz.icu/img/other/1d-col.png)
2024-04-30 15:31:46 +03:00
## Conclusion (How To Try?)
You can try the simulator [here](https://od-collisions.arbuz.icu/).
2024-04-29 21:22:06 +03:00
---
## Note
2024-04-29 22:28:43 +03:00
* If you decide to use this project as the basis of your project, it would be advisable to [contact me](https://arbuz.icu/mail) first.
2024-04-29 21:26:41 +03:00
2024-04-29 23:16:27 +03:00
* If you have any interesting projects that I could be involved in, or if you would like to contact me, you can do so [here](https://arbuz.icu/mail).
2024-04-30 15:31:46 +03:00
* You can find the project files in the [repository on Github](https://github.com/grey-cat-1908/collisions-fool-)
2024-04-30 09:04:35 +03:00
## Reference
2024-04-30 10:39:45 +03:00
[^1]: Galperin, G. A., _[PLAYING POOL WITH π (THE NUMBER π FROM A BILLIARD POINT OF VIEW)](http://rcd.ics.org.ru/RD2003v008n04ABEH000252/)_, _Regular and Chaotic Dynamics_, 2003, vol. 8, no. 4, pp. 375-394.
2024-04-30 10:37:01 +03:00
[^2]: Landau, L.D. and Lifshitz, E.M., _Course of Theoretical Physics_, vol. 1: _Mechanics_, Elsevier Science, 1982.
2024-04-30 15:02:50 +03:00
2024-04-30 15:16:47 +03:00
[^3]: _p5.js_, Processing Foundation, accessed 30 April 2024, <https://p5js.org/>
[^4]: Mozilla Corporation, _Window: localStorage property_, accessed 30 April 2024, <https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage>