https://github.com/strandedkitty/tiles-intersect
Find all tiles or voxels intersected by a line segment
https://github.com/strandedkitty/tiles-intersect
algorithms javascript
Last synced: 10 months ago
JSON representation
Find all tiles or voxels intersected by a line segment
- Host: GitHub
- URL: https://github.com/strandedkitty/tiles-intersect
- Owner: StrandedKitty
- License: mit
- Created: 2019-10-03T17:20:42.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-06T17:29:17.000Z (about 3 years ago)
- Last Synced: 2023-03-10T04:36:55.256Z (almost 3 years ago)
- Topics: algorithms, javascript
- Language: JavaScript
- Homepage:
- Size: 146 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tiles-intersect
Given two points which represent a line in 2D or 3D space find all tiles/voxels it intersects. It's a JavaScript implementation of [A Fast Voxel Traversal Algorithm for Ray Tracing](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.42.3443&rep=rep1&type=pdf).
## Usage
```javascript
const tilesIntersect = require('tiles-intersect');
let line = [[0.1, 0.2], [3.5, 2.8]];
let tiles = tilesIntersect.calculate(line, 2); // [[0, 0], [1, 0], [1, 1], [2, 1], [2, 2], [3, 2]]
```
## API
### `calculate(line, dimensions = 2)`
Returns a 2D array of tiles/voxels intersected by a line.
#### line
Two-dimensional array which contains two points.
#### dimensions
Number of dimensions (2 or 3).