2D Physics Sandbox
A fast, interactive 2D physics sandbox online. Simulate gravity, rigid body collisions, and object stacking in real time, directly in your browser.
How Do Physics Engines Work?
A physics engine is a complex computer program that simulates Newtonian physics models—using variables like mass, velocity, friction, and restitution (bounciness). These engines are the backbone of modern video games, animated movies, and scientific simulations.
This tool uses Matter.js, a highly optimized 2D physics engine written purely in JavaScript. It allows for rigid body collision detection, constraint modeling, and real-time interaction.
Rigid Bodies
In a simulation, objects are "rigid bodies." This means they do not deform upon collision. Instead, the engine calculates the exact moment of intersection and applies mathematical forces to push them apart, mimicking a bounce or a crash.
Gravity
Gravity is a constant vector force applied to every non-static body in the world during every frame of the simulation (usually 60 times a second). Turning off gravity shows how momentum carries objects infinitely in a vacuum.
Restitution (Bounciness)
When objects collide, some kinetic energy is lost to heat and sound in the real world. In physics engines, this is modeled as "restitution." A restitution of 1 means a perfectly elastic bounce, while 0 means it stops dead.
Mouse Constraints
Dragging an object uses a "mouse constraint." Instead of directly moving the object to your cursor, the engine acts like an invisible spring is pulling the object toward your mouse. This ensures the object still collides properly with walls.
Tech Stack Used to Build This Tool
JavaScript + Matter.js
The simulation engine is written in JavaScript and powered by Matter.js for rigid body dynamics, constraints, collision resolution, and gravity handling.
HTML5 Canvas + PHP + Tailwind CSS
Rendering happens on HTML5 Canvas, the page is served with PHP templates, and the interface uses utility-first Tailwind classes for responsive UI controls.
Frequently Asked Questions
Check Out Other Popular Tools
Free Text to Speech
Convert any text to natural speech instantly in your browser. Choose from 50+ voices and languages. Free, private, no sign-up required.
Word Problem Solver
Text-based word problem solver with step-by-step math explanations for arithmetic, percentages, and rates.
Cat Name Generator
Find the purr-fect name for your feline friend! Generate unique names for cats based on gender, color, and personality.
Was this tool helpful?
Comments
Loading comments...