Explore real-time 3D rotational mechanics, elastic collisions, and procedural acoustics directly inside the interactive simulation above. Whether you want to test how centrifugal inertia pins heavy particles against a spinning wireframe cage, trigger chain-reaction collisions across five zero-gravity spheres, or generate dynamic stereo chimes from pure physics math, you can customize every parameter on the fly.
![]() |
| 3D Ball Simulation Sandbox |
How to Use the Simulation: Quick-Start Controls & Keys
You can interact directly with the canvas using your mouse or touchscreen, or open the Controls drawer in the top-right corner to fine-tune individual physics variables.
Direct Canvas Gestures & HUD Buttons
| Action / Button | Desktop (Mouse) | Mobile / Tablet (Touch) | What It Does |
|---|---|---|---|
| Burst Spawn | Left-Click inside any sphere | Tap inside any sphere | Instantly injects 5 new balls from the glowing center emitter core. |
| Spin & Tilt Cage | Click + Drag on a sphere | Touch + Drag on a sphere | Manually overrides rotation speed and tilts the 3D grid axis in real time. |
| Fling Spheres (Multi-Mode) | Click + Drag + Release | Touch + Drag + Release | Grabs an entire sphere and throws it into neighboring spheres or container walls. |
| Audio Toggle ( / ) | Click top-right icon or status pill | Tap top-right icon or status pill | Enables or mutes real-time synthesized collision sound effects. |
| Pause / Resume (⏸️ / ▶️) | Click top-right pause button | Tap top-right pause button | Freezes all physics calculations so you can inspect mid-air collisions or adjust sliders. |
| Clear Balls (️) | Click top-right trash icon | Tap top-right trash icon | Empties all active spheres immediately for a clean slate. |
| Controls Panel (⚙️ Controls) | Click top-right pill button | Tap top-right pill button | Shows or hides the settings drawer for an unobstructed view. |
| Fullscreen (Bottom-Right) | Click bottom-right corner icon | Tap bottom-right corner icon | Expands the simulation to fill your entire display; press Esc or click again to exit. |
Control Panel Sliders & Modes Explained
- Multi-Sphere Mode (
Off/On): Switches from a single centered sphere (holding up to 200 balls) into a zero-gravity arena containing 2, 3, 4, or 5 independent spheres. To keep frame rates smooth across desktop and mobile browsers, Multi-Sphere Mode caps each individual sphere at 60 balls (up to 300 active particles total across 5 spheres) and assigns each cage a distinct color theme (Cyan, Purple, Emerald, Amber, and Rose). - Sphere Size (
0.50x–2.00x): Scales the diameter of every sphere in Multi-Sphere Mode. An automatic overlap-relaxation solver gently separates neighboring spheres as they grow so they never clip into one another. - Sphere Bounciness (
0.20–1.05): Sets how much kinetic energy is preserved when spheres bounce off the four container walls or collide with each other. Values below1.00gradually slow the spheres down,1.00creates perpetual elastic motion, and1.05introduces super-elastic acceleration. - Spawn Rate (
0–25 /s): Controls how many balls per second emerge from each sphere's central emitter. Slide it to0 /swhen you want to study a closed system with a fixed number of particles. - Sphere Spin Speed (
-5.0to+5.0 rad/s): Adjusts the rotational velocity of the gridded cage. Negative values spin clockwise,0halts rotation completely, and positive values spin counter-clockwise. - Ball Weight / Mass (
0.2–5.0 kg): Modifies particle inertia, air resistance, and surface friction against the spinning inner wall. Heavy balls resist air drag better and grip the rotating wall more aggressively. - Ball Size / Radius (
5–22 px): Changes both the visual diameter and physical collision radius of every ball in real time. - Internal Gravity (
0.0–2.5 G): Controls downward pull inside each sphere—ranging from weightless orbital drift (0.0 G) to Earth gravity (1.0 G) and high-gravity compression (2.5 G). - Ball Bounciness (
0.10–0.98): Sets the internal coefficient of restitution for ball-to-ball and ball-to-wall rebounds. - Ball Color & Rainbow Mix ( Mix): Lets you pick a preset swatch, choose any custom hex color from the color picker, or toggle Mix mode to cycle through the full color spectrum as new balls spawn.
![]() |
| Multimode - Spehere Simulation |
6 Physics Experiments & Possibilities to Try
Because every slider updates live without resetting your particles, you can build dramatically different physical environments in seconds:
-
The Centrifuge Wall-Cling Experiment: Set Single Sphere Mode with Spin Speed at
5.0 rad/s, Internal Gravity at0.2 G, Ball Weight at4.5 kg, and Ball Bounciness at0.40. Heavy balls pick up tangential velocity from the rotating grid, climb the inner curvature, and form a revolving equatorial ring held outward by inertia—demonstrating the same principle used in artificial-gravity space station concepts. -
Zero-Gravity Ideal Gas Simulation: Set Internal Gravity to
0.0 G, Ball Bounciness to0.98, Ball Size to7 px, and Spawn Rate to15 /s(then drop to0 /sonce 150+ balls fill the sphere). Without gravity pulling particles downward, balls distribute evenly throughout the 3D volume, colliding elastically and illustrating kinetic molecular theory and Brownian motion. -
Super-Elastic Particle Accelerator (Overspeed Reset Test): Turn on Multi-Sphere Mode with
4or5spheres, Sphere Size at1.15x, and Sphere Bounciness at1.05. Each wall or inter-sphere collision multiplies velocity by1.05x, creating a chaotic chain reaction where spheres ricochet faster and faster while sloshing the balls trapped inside. Once any sphere reaches 4,200 px/s (3x standard speed), the safety monitor triggers⚠️ Speed too high! Simulation reset.to prevent physics tunneling. -
Heavy vs. Light Momentum Transfer: Spawn 15 small light balls (Weight
0.3 kg, Size6 px), then raise Weight to5.0 kgand Size to20 pxand click inside the sphere to burst-spawn giant heavy spheres. Because collisions are mass-weighted, the heavy spheres plow through lighter particles with minimal deflection while launching lightweight balls across the cage at high speed. -
Procedural Ambient Wind Chime: Enable Audio (), set Spawn Rate to
3 /s, Sphere Spin Speed to0.8 rad/s, Internal Gravity to0.6 G, and activate Mix color mode. As balls of varying radii and speeds bounce across the left and right hemispheres, the built-in synthesizer generates stereo-panned harmonic tones proportional to impact velocity and mass. -
5-Sphere Inertial Sloshing Arena: Enable Multi-Sphere Mode with
5spheres, Sphere Size at0.85x, Sphere Bounciness at0.95, and Internal Gravity at1.2 G. Watch five independent gravitational environments collide in 2D space—every time two outer cages strike one another, the sudden change in momentum throws all 60 internal balls against the opposite wall of their container.
Under the Hood: The Physics & Math Powering the Simulation
This simulation runs without pre-rendered animations or external game engines. Every frame is calculated from scratch using Newtonian mechanics, 3D linear algebra, and multi-substep numerical integration.
1. 3D Rotation Matrices & Gram-Schmidt Orthonormalization
The gridded sphere is defined by latitude and longitude polylines mapped onto a 3D sphere of radius R = 220 units. On each physics substep, the sphere rotates around an arbitrary 3D angular velocity vector ω = (ωx, ωy, ωz) using Rodrigues' rotation formula to update a 3×3 transformation matrix. To prevent floating-point rounding errors from gradually skewing or stretching the sphere after thousands of rotations, the engine runs a Gram-Schmidt orthonormalization pass on every substep to keep all three basis vectors strictly perpendicular and unit-length.
2. Tangential Wall Friction & Centrifuge Transfer
When a ball strikes the inner boundary of the rotating sphere at position vector r, the wall is moving with a tangential surface velocity determined by the cross product of the sphere's angular velocity and the impact point:
By computing the ball's velocity relative to the moving wall (vrel = vball − vsurface), the engine splits the impact into a normal rebound component and a tangential grip component. Heavier balls experience stronger surface grip, allowing the spinning grid to drag them upward along the inner curvature.
3. Mass-Weighted 3D Elastic Collisions
When two balls A and B overlap in 3D space (d < rA + rB), the solver first resolves positional penetration proportionally to their inverse masses (1/mA and 1/mB) so heavy balls stay grounded while lighter balls displace outward. It then calculates the scalar collision impulse j along the collision normal n using the coefficient of restitution e:
4. Non-Inertial Frame Sloshing in Multi-Sphere Mode
In Multi-Sphere Mode, each sphere acts as a moving reference frame in a zero-gravity 2D plane. When a sphere rebounds off a container wall or another sphere and experiences a sudden velocity change Δvsphere, every ball inside receives a proportional fictitious inertial impulse (−Δvsphere). This replicates the real-world fluid-like sloshing seen when shaking a sealed glass globe.
5. Multi-Substep Integration & Runaway Speed Protection
Fast-moving objects in discrete-time simulations can suffer from tunneling—passing straight through a wall between two rendered frames. To prevent this, each visual frame is divided into 10 outer substeps for high-speed Multi-Sphere collisions and 5 inner substeps for 3D ball-to-ball physics. Furthermore, when Sphere Bounciness is set to 1.05, kinetic energy grows exponentially (Ek = ½mv2). Monitoring peak velocity against a 4,200 px/s ceiling ensures the simulation resets cleanly with a warning alert before numerical overflow can occur.
Procedural Sound Synthesis: How Audio Works Without MP3 Files
Every chime, thud, and alert in this simulation is synthesized mathematically in real time using the browser's native Web Audio API—meaning zero external audio files, zero copyright restrictions, and instant loading:
- Dual-Oscillator Harmonic Timbre: Each impact triggers a primary sine-wave oscillator paired with a secondary overtone oscillator tuned to a
2.41xnon-integer harmonic ratio, producing a crystalline glass-and-metal resonance. - Mass & Velocity Pitch Mapping: Larger, heavier balls produce lower fundamental frequencies, while small balls emit crisp high-pitched pings. Impact speed scales both peak volume and a rapid downward pitch envelope.
- Real-Time Stereo Panning & Compression: Impacts on the left side of the canvas pan to your left speaker or earbud, and impacts on the right pan right. A built-in
DynamicsCompressorNodeand polyphony limiter prevent audio distortion even when hundreds of balls collide simultaneously.
Frequently Asked Questions
Why is the sound muted when the page first loads?
Modern web browsers (Chrome, Safari, Firefox, and Edge) block websites from playing audio automatically until the user clicks or taps on the page. Clicking anywhere inside the simulation canvas or tapping the / Audio: Off button unlocks the Web Audio synthesizer immediately.
Why does the simulation reset with a "Speed too high!" warning?
When you set Sphere Bounciness to 1.05 in Multi-Sphere Mode, each collision adds 5% more velocity instead of losing energy. Within several seconds, spheres exceed 4,200 pixels per second. The built-in safety watchdog detects this runaway kinetic energy spike and automatically resets the spheres to prevent visual glitches or browser lag.
Can I run this simulation on mobile devices and tablets?
Yes. The simulation uses a responsive ResizeObserver canvas that automatically scales to fit narrow mobile screens, blog columns, or full-screen desktop monitors, with full multi-touch support for dragging spheres and burst-spawning balls.
Why is the ball limit 200 in Single Mode and 60 per sphere in Multi-Mode?
3D ball-to-ball collision detection compares pairs of particles across multiple physics substeps every frame. Capping Single Mode at 200 balls and Multi-Mode at 60 balls per sphere (up to 300 balls across 5 spheres) ensures smooth 60 FPS performance even on mid-range smartphones and laptops without overheating your device.


Comments
Post a Comment