Skip to content

Runnable Examples

After cloning the repository, you can run the following examples to see how fastquadtree works in practice.

Environment Setup

Clone the repo

git clone https://github.com/Elan456/fastquadtree.git
cd fastquadtree

Create and activate a virtual environment, install dependencies (uv)

uv installation instructions

uv will manage a virtual environment for you. To set it up, run:

uv sync --group interactive 

1. Interactive demo

  • Add and delete boids with mouse clicks
  • Visualize KNN and range queries

The interactive demo is a great way to see how fastquadtree works in practice. You can see how the quadtree subdivides as you add points, and validate the accuracy of the queries visually. By pressing 1, you can visualize the KNN query for each boid.

uv run python interactive/interactive_v2.py

Interactive_V2_Screenshot

1.5 Interactive Demo with Rectangles

  • Similar to the above demo, but uses rectangles instead of points
  • If the rectangles intersect at all with the query area, they will be highlighted in red

If you are creating a game or simulation environment where entities have bounding boxes, you can use the rectangular quadtree to quickly check which entities are intersecting with another.

uv run python interactive/interactive_v2_rect.py

Interactive_V2_Rect_Screenshot

2. Ball Pit

  • Spawn balls in a pit with physics-based collisions
  • Easily switch between brute force and quadtree collision detection to see the performance difference

The ball pit demo shows how quadtrees offer massive performance improvements for collision detection. Rectangular queries are used to find potential collisions, and then precise circle-circle collision checks are performed.

uv run python interactive/ballpit.py

Ballpit_Demo_Screenshot