Balls Bouncing off Walls

The patterns here are suggested by collisions of colored balls according to the laws of mechanics. Balls with diverse sizes and colors fall under the influence of customizable acceleration due to gravity. They can hit up to three projection walls and bounce back. If a ball leaves the cube, it disappears. Balls interact only with the walls but not with one another. There are several effects that you can set for the projection walls.


  • [Snapshot]
  • [Snapshot]
  • [Snapshot]


The collision between a ball and a projection wall surface changes only the velocity vector component along the normal direction at the point of collision on . Before the collision, if the ball's velocity vector is and the unit normal at is , then can be written as where and . After collision, the velocity vector becomes . If the projection wall surface is a plane, then determining an accurate collision point is easy; but if is curved surface, this can be somewhat time-consuming and yields little benefit since the ball's radius is relatively small when compared to the simulation region. Therefore to calculate more quickly, we simply use the sphere center's coordinate and a that is obtained by solving the equation as the point of collision.
When a ball hits more than one wall at once, we treat the multiple collisions as follows: if all walls are planes, we write and change it to where or according to which collision happens along the direction. If a wall is a curved surface, then we first deal with the collision on this surface alone using the method described in the previous paragraph and then deal with the remaining collisions on the plane walls.
This Demonstration is inspired by "Create Unique Charts with Different Visualizations" and "Use Symbolic Graphics Primitives to Visualize Results". A few videos of this Demonstration can be downloaded from the author's personal page.
Possible Issue
The reset button may flicker once after it is clicked, but this does not cause any trouble.
    • Share:

Embed Interactive Demonstration New!

Just copy and paste this snippet of JavaScript code into your website or blog to put the live Demonstration on your site. More details »

Files require Wolfram CDF Player or Mathematica.

Mathematica »
The #1 tool for creating Demonstrations
and anything technical.
Wolfram|Alpha »
Explore anything with the first
computational knowledge engine.
MathWorld »
The web's most extensive
mathematics resource.
Course Assistant Apps »
An app for every course—
right in the palm of your hand.
Wolfram Blog »
Read our views on math,
science, and technology.
Computable Document Format »
The format that makes Demonstrations
(and any information) easy to share and
interact with.
STEM Initiative »
Programs & resources for
educators, schools & students.
Computerbasedmath.org »
Join the initiative for modernizing
math education.
Step-by-Step Solutions »
Walk through homework problems one step at a time, with hints to help along the way.
Wolfram Problem Generator »
Unlimited random practice problems and answers with built-in step-by-step solutions. Practice online or make a printable study sheet.
Wolfram Language »
Knowledge-based programming for everyone.
Powered by Wolfram Mathematica © 2018 Wolfram Demonstrations Project & Contributors  |  Terms of Use  |  Privacy Policy  |  RSS Give us your feedback
Note: To run this Demonstration you need Mathematica 7+ or the free Mathematica Player 7EX
Download or upgrade to Mathematica Player 7EX
I already have Mathematica Player or Mathematica 7+