Visible regions for 2D poly-lines
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
Try out the module yourself in your browser:
Just install it using npm:
npm install vishull2d
Then you can use it in your game like this:
var vishull = require"vishull2d"//Line segments are encoded as pairs of arraysvar lines =10 10 10 -10//Compute visible hull from the point [0,0]var region = vishulllines 00
Computes the visible hull from the point
segmentsis a collection of line segments
centeris 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.
(c) 2013 Mikola Lysenko. MIT License