rabbyt.collisions - Rabbyt Reference

Documentation Index

# rabbyt.collisions

This module provides some functions for collision detection.

## Functions

### 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`.

### 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)]`.