Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yujota/elm-collision-detection
Collision detection library for elm.
https://github.com/yujota/elm-collision-detection
collision-detection elm
Last synced: about 1 month ago
JSON representation
Collision detection library for elm.
- Host: GitHub
- URL: https://github.com/yujota/elm-collision-detection
- Owner: yujota
- License: bsd-3-clause
- Created: 2020-04-29T01:02:44.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-02-25T17:47:33.000Z (almost 4 years ago)
- Last Synced: 2024-08-01T13:24:35.400Z (4 months ago)
- Topics: collision-detection, elm
- Language: Elm
- Size: 5.32 MB
- Stars: 11
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ccamel - yujota/elm-collision-detection - Collision detection library for elm. (Elm)
README
# elm-collision-detection
This Elm library provides Quadtree space partitioning data structure for efficient collision detection on a 2D system.
[Live demo](https://yujota.github.io/elm-collision-detection/)
![example-demo-image](https://github.com/yujota/elm-collision-detection/blob/master/images/example-demo.gif?raw=true)
## Overview
Let's suppose there are six objects and you want to detect collisions.
On a naive approach which is the method to check all possible combinations, it needs to inspect `6C2 = 15` patterns.
As the number of objects increases, this process takes much longer(`nC2 ≒ n^2`).
So, it is necessary to reduce the number of checks.One solution is that check objects only nearby.
For example, space partitioning.In the figure below there is a purple circle.
In a naive approach, we have to check all the other 5 objects to find collisions with the purple one
but these triangles are far away from it.
![overview](https://github.com/yujota/elm-collision-detection/blob/master/images/overview.png?raw=true)
![overview-with-grid](https://github.com/yujota/elm-collision-detection/blob/master/images/overview-with-grid.png?raw=true)Instead, we divide 2D space into small regions and check objects in each region.
This is how space partitioning works and this library adopts Quadtree as a data structure to store objects.
The implementation of Quadtree is capsulated and you don't have to aware of it.(If you're an expert on this topic and find some problems in this code, please pull-request :D)
## Performance
This module has not completely optimized yet,
but it seems that `detectCollisions` for QuadTree container is faster than one for the naive approach.
The benchmark code is available on [elm-collision-detection/benchmarks/Benchmarks/DetectCollisionsWithSmallRectangle.elm](https://github.com/yujota/elm-collision-detection/blob/master/benchmarks/Benchmarks/DetectCollisionsWithSmallRectangle.elm).![performance-result](https://github.com/yujota/elm-collision-detection/blob/master/images/performance-result.png?raw=true)