Book Image

Sage Beginner's Guide

By : Craig Finch
1 (1)
Book Image

Sage Beginner's Guide

1 (1)
By: Craig Finch

Overview of this book

Table of Contents (17 chapters)
Sage Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – detecting collisions between spheres


We will use collision detection as an example to demonstrate some common optimization techniques. Detecting collisions is an important part of Monte Carlo simulations, that are used in physics and chemistry to simulate the motion of molecules and particles. Collision detection is also used in flight simulators and video games. It is easy to detect collisions between spheres, so most collision detection algorithms define a "bounding sphere" around each complex object, and check for intersections between the bounding spheres. If the bounding spheres intersect, then more computationally expensive calculations are used to determine whether or not the objects themselves actually overlap.

This example is designed to be run from the notebook interface. First, let's create a box full of randomly placed spheres. The number of spheres is set so that the example runs in a reasonable length of time on a 2009 MacBook Pro. You may need to adjust the...