This is a very simple and straight forward program. It is about simulation 3D bouncing balls inside a box. First, there is only one ball inside box, it randomly placed inside the box, and it also has some random velocity, and randcom colors to begin with.
Basically, the box is represented by 6 planes, where each plane has a normal associated with it.
A plane is represented by a point (which lies on plane) and a normal of the plane.
Each ball has its own current position, previous position, velocity, acceleration and color
associated with each ball
For each ball, we compute the direction of ball and new velocity of each time step.
In order to
determine whether there is a collision or not, we use the following formula. We take the dot product
between the normal of a plane and the direction of a ball.
If the result of the dot product is zero,
then it means that the direction is perpendicular with the normal of the plane. In other words,
the ball will not collide with the plane since it travel parallel with the plane.
If the result of the dot product is not equal to zero, then we have collision between the plane and
the ball. For each time frame, we compute the dot product of each ball with all the planes, i.e.,
6 sides of box, to determine whether there is a collision or not.
A movie clip showing the program can be found here