The Camtasia Studio video content presented here requires JavaScript to be enabled and the latest version of the Macromedia Flash Player. If you are you using a browser with JavaScript disabled please enable it now. Otherwise, please update your version of the free Flash Player by downloading here.

Since Vpython has vectors as a data type, a task like collision detection, which would normally be quite cumbersome, becomes straightforward. Here's the syntax for detecting a collision between two objects named i and j with position vectors denoted by i.pos and j.pos:

if mag(i.pos-j.pos) <= i.radius + j.radius:

The force reflecting the balls is also aligned along the difference vector. Note that the language is aligned to the task.