# Collision Detection using Sweep and Prune

**URL:** <https://discourse.processing.org/t/collision-detection-using-sweep-and-prune/49119>\
**Category:** Gallery\
**Created:** [August 5, 2026, 2:41pm UTC](https://discourse.processing.org/t/collision-detection-using-sweep-and-prune/49119 "2026-08-05T14:41:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [August 5, 2026, 2:41pm UTC](https://discourse.processing.org/t/collision-detection-using-sweep-and-prune/49119/1 "2026-08-05T14:41:48Z")

</div>

This is a companion sketch to my last [post](https://discourse.processing.org/t/collision-detection-using-spatial-hashing/49088) on the spatial hashing algorithm. It uses the same core code for the particle and vector classes.

If you want to know how the sweep and prune works then look at this [video](https://www.youtube.com/watch?v=MKeWXBgEGxQ&t=6s), I created my code based on the description in the video.

This sweep and clean appears to perform better than the spatial hash algorithm, at least for the initial conditions used in both sketches.

https://editor.p5js.org/quark-js/full/xrs5sqWW5
