C2: Collision Detection Library

Due Tuesday, February 10th, at the start of class.

It is now time to write (in code) what you figured out in D2. Particularly, you will be creating a SALD library, 'collide.js', that implements collision detection functions for circles, rectangles, convex polygons, and rays, represented as follows:

What to write

Fill in the stub functions in collide.js, available in the SALD repository, which perform collision checks between shapes of the same type, and between rays and shapes of all types.

For your convenience, I've created a SALD project which exercises the collision library in a very basic way: sald-collision-test. I wouldn't expect this to catch all possible bugs, but it does provide a basic sanity check.

How to hand it in

Fork SALD to your own github account and make your changes in that fork. (If you already have a fork, make sure to pull the latest from my repository to get the stub 'collide.js'.)

Bring a print out of your filled-in collide.js to class with your name (and the location of your forked repo) written on it.

Supporting Material

Source code from Box2D.

A fine basis for collision detection is the separating axis theorem.

If you don't want to implement a bunch of different tests, the GJK algorithm can be used to perform all of these checks (among others). However, it is tricky to get right, and likely somewhat slow for the simple cases.