Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mikolalysenko/vishull2d
Visible regions for 2D poly-lines
https://github.com/mikolalysenko/vishull2d
Last synced: about 2 months ago
JSON representation
Visible regions for 2D poly-lines
- Host: GitHub
- URL: https://github.com/mikolalysenko/vishull2d
- Owner: mikolalysenko
- License: mit
- Created: 2013-04-02T07:07:12.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-01-30T13:37:03.000Z (almost 10 years ago)
- Last Synced: 2024-10-20T14:27:57.508Z (2 months ago)
- Language: JavaScript
- Homepage: http://mikolalysenko.github.com/vishull2d/
- Size: 155 KB
- Stars: 17
- Watchers: 4
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
vishull2d
=========
Computes the visible region from a point for a given environment represented by a collection of line segments. [Based on Amit Patel's blog post](http://simblob.blogspot.com/2012/07/2d-visibility.html)Try out the module yourself in your browser:
http://mikolalysenko.github.com/vishull2d/
Use
===
Just install it using npm:npm install vishull2d
Then you can use it in your game like this:
```javascript
var vishull = require("vishull2d")//Line segments are encoded as pairs of arrays
var lines = [
[[10, 10], [10, -10]]
]//Compute visible hull from the point [0,0]
var region = vishull(lines, [0,0])
```### `require("vishull2d")(segments, center)`
Computes the visible hull from the point `center`* `segments` is a collection of line segments
* `center` is the point from which the visibility is computed**Returns:** A counter-clockwise oriented simple polygon representing the visible region.
**Note** This code assumes that all segments intersect only at their end points. If you have any crossings, you will need to detect them and split them yourself.
Credits
=======
(c) 2013 Mikola Lysenko. MIT License