Linear Momentum
While playing the game of Pong, have you ever wondered how the Computer figures out the final location of the ball? It uses conservation of Linear Momentum. The "game" below shows you the calculated trajectory of the ball.
Touch the canvas with the intended position of your paddle
Description
According to conservation of linear momentum, the vector sum of linear momenta of a system of isolated particles is conserved. Although the direction and momentum of induvidual particles may change during collisions, the sum of components of linear momentum of the colliding particles remains same before and after the collision.
\[ \sum m_i \vec{v}_i = constant \]When colliding with a vertically-oriented, ideally rigid and immovable obstacle, the sign of momentum along the horizontal direction changes whereas the momentum along vertical direction remains the same
Working of the game
The game assumes the paddles and the walls to be rigid and immovable objects. The function that controls the paddle has access to the initial coordinates and the initial horizontal and vertical velocity of the ball. It creates a pseudo-ball and tracks its motion. Assuming that the player manages to dodge the pseudo-ball, the function negates its vertical velocity. In the meantime, if the ball collides with the wall, the function negates its horizontal velocity. It continues mapping the trajectory of the pseudo-ball until the ball reaches the Y-coordinate of the paddle. The X-coordinate of the ball at this point is set as target for the paddle. All these calculations happen in the blink of an eye and only once for every oscillation of the ball.
Note:
- To prevent the game from becoming boring, the vertical speed of the ball is increased periodically by some percentage. In such cases, the trajectory of the ball is recalculated
- The simulation may lag on low-end devices
Developed by ChanRT | Fork me at GitHub