Documentation Index

rabbyt.collisions

This module provides some functions for collision detection.

Functions

aabb_collide

aabb_collide(objects)

aabb_collide works similar to collide, but instead of using bounding radius it uses axis aligned bounding boxes [AABB].

All objects must have left, top, right, and bottom attributes.

collide

collide(objects) -> list of collisions

Collides objects, first using rdc() and then using brute_force().

Each object should have the attributes x, y, bounding_radius, and bounding_radius_squared.

collide_single

collide_single(single, objects)

Finds collisions between a single object and a list of objects.

single can either be an object with x, y, and bounding_radius attributes, or a tuple of (x,y, bounding_radius) (In both cases, bounding_radius is optional and defaults to 0.)

rdc

rdc(objects, [max_depth,] [min_split]) -> list of collision groups

Uses the Recursive Dimensional Clustering algorithm to find groups of colliding objects.

objects should be a list of objects. Each object should have the attributes x, y, and bounding_radius.

If the number of objects in a collision group is less than min_split, recursion will stop. This defaults to 1, but in practice, it is usually faster to just use a brute force method once a group gets down to 10 objects.

max_depth is the maximum number of recursions to make. It defaults to 0, which is infinite.

Instead of returning individual collisions, rdc() returns groups (lists) of colliding objects. For example, if A collides with B and B collides with C, one of the groups will be [A, B, C], even though A and C don't directly collide.

Also, each object is returned at most once. If it is in one group, it won't be in any other. An object without any collisions isn't returned at all.

brute_force

brute_force(objects) -> list of collisions

Finds collisions between objects using a brute force algorithm.

objects should be a list of objects, each of which have the attributes x, y, and bounding_radius_squared. Each object is checked against every other object.

For example, if A collides with B, B collides with C, and D doesn't collide with anything, the result will be: [(A, B), (B, C)].