Javascript Physics Simulator
For a fullscreen view, click here.
In this simulation, I wanted to capture the real-life behavior of a bouncing ball by applying some basic principles from physics and dynamics. I started by simulating gravity; I increment the ball’s downward velocity each frame to mimic how objects accelerate when they fall. To make the motion feel more realistic, I also implemented friction. I used a damping coefficient of 0.98 for both horizontal and vertical velocities, which means that with every frame the ball’s speed is reduced to 98% of what it was. This slight reduction simulates energy losses—just like air resistance or surface friction would in a physical system—providing a foundation for how energy dissipates in real-world dynamics.
Handling collisions was another key aspect of my project. I programmed the ball so that when it reaches the boundaries of the canvas or enters a predefined bucket area, its velocity reverses direction to create a bouncing effect. This simple collision response mirrors the way momentum is transferred during an impact. The frictional damping factor of 0.98 is particularly important here because it represents a nearly elastic collision, where the ball retains most of its energy but still loses a little bit with each bounce. In my simulation, this elasticity factor is essential—it reflects a realistic compromise between a perfectly elastic bounce (which is rare in real-world scenarios) and a completely inelastic collision where the ball wouldn’t bounce at all.
I also incorporated rotation into the simulation. As the ball bounces, I gradually update an angle variable and use trigonometry to calculate the positions of the dimples on the ball. This detail offers a visual representation of angular momentum and helps connect the concepts of linear and rotational motion. Seeing the ball spin as it moves gives a dynamic quality to the simulation, demonstrating how objects in motion can rotate and translate simultaneously—a principle that is central to many mechanical engineering applications.
Finally, I added an interactive element by allowing users to click and drag the ball. When the user drags the ball, its velocity is reset and then recalculated based on the mouse movement, effectively simulating an impulse. This interactivity not only makes the simulation more engaging, but it also illustrates the concept of impulse and momentum transfer—key concepts that I’ve studied in dynamics courses. Overall, this project is my practical demonstration of how the principles of dynamics and physics can be translated into a working simulation, bridging theory with real-time, interactive application.