All Projects → trylock → Visibility

trylock / Visibility

Licence: mit
Simple sweep line visibility polygon algorithm implementation

Projects that are alternatives of or similar to Visibility

Cgal
The public CGAL repository, see the README below
Stars: ✭ 2,825 (+4456.45%)
Mutual labels:  polygon, computational-geometry
Martinez
Martinez-Rueda polygon clipping algorithm, does boolean operation on polygons (multipolygons, polygons with holes etc): intersection, union, difference, xor
Stars: ✭ 391 (+530.65%)
Mutual labels:  polygon, computational-geometry
polygon-splitter
A small (<10kb minified) javascript library for splitting polygons by a polyline.
Stars: ✭ 20 (-67.74%)
Mutual labels:  polygon, computational-geometry
Earcut
The fastest and smallest JavaScript polygon triangulation library for your WebGL apps
Stars: ✭ 1,359 (+2091.94%)
Mutual labels:  polygon, computational-geometry
Polysnap
A work in progress polygon operations library with integer snap-rounding
Stars: ✭ 14 (-77.42%)
Mutual labels:  polygon, computational-geometry
Kdbush
A fast static index for 2D points
Stars: ✭ 412 (+564.52%)
Mutual labels:  computational-geometry
Angular Canvas Area Draw
Simple library to draw polygons over image with canvas
Stars: ✭ 21 (-66.13%)
Mutual labels:  polygon
Qhull
Qhull development for www.qhull.org -- Qhull 8.0.2 (2020.2 candidate) at https://github.com/qhull/qhull/wiki
Stars: ✭ 400 (+545.16%)
Mutual labels:  computational-geometry
Rectlabel Support
RectLabel - An image annotation tool to label images for bounding box object detection and segmentation.
Stars: ✭ 338 (+445.16%)
Mutual labels:  polygon
Phidl
Python GDS layout and CAD geometry creation
Stars: ✭ 56 (-9.68%)
Mutual labels:  polygon
Geometry2d
Unity3D: A set of helper classes for 2D geometric calculations.
Stars: ✭ 40 (-35.48%)
Mutual labels:  polygon
Pympc
Stars: ✭ 26 (-58.06%)
Mutual labels:  computational-geometry
Earcut.hpp
Fast, header-only polygon triangulation
Stars: ✭ 447 (+620.97%)
Mutual labels:  polygon
Wxdraw
几何画图(微信小程序)
Stars: ✭ 36 (-41.94%)
Mutual labels:  polygon
Hmm
Heightmap meshing utility.
Stars: ✭ 403 (+550%)
Mutual labels:  computational-geometry
Flatbush
A very fast static spatial index for 2D points and rectangles in JavaScript
Stars: ✭ 1,031 (+1562.9%)
Mutual labels:  computational-geometry
Aabb Tree
A d-dimensional aabb-tree implementation for MATLAB.
Stars: ✭ 5 (-91.94%)
Mutual labels:  computational-geometry
Polytri
🔺 Fast and simple polygon triangulation library.
Stars: ✭ 37 (-40.32%)
Mutual labels:  computational-geometry
Turf
A modular geospatial engine written in JavaScript
Stars: ✭ 6,659 (+10640.32%)
Mutual labels:  computational-geometry
Wicket
A modest library for moving between Well-Known Text (WKT) and various framework geometries
Stars: ✭ 484 (+680.65%)
Mutual labels:  polygon

Visibility Polygon

Build Status

Simple sweep line Visibility polygon algorithm implementation. My inspiration for the project was this 2d Visibility article on the Red Blob Games website. This was my semestral work for lecture Algorithms and Data Structures II at MFF UK.

The project is separated into 2 subprojects: visibility (header-only library) and tests.

Main idea of the algorithm

  • Input: set of line segments (obstacles) and a position of an observer.
  • Output: visibility polygon (i.e. largest polygon s.t. a line segment from the observer's position to any point in the polygon does not intersect any obstacle)

First, we sort endpoints of the line segments (obstacles) in CW order where the observer's position is the center point. Line segment endpoint whose other endpoint is greater in this CW order is called a start vertex. Otherwise it's an end vertex.

Visibility polygon is found using a sweep line algorithm. The sweep line here is a ray. Its origin is at the observer's position and it rotates around this point. The algorithm keeps a state which is a set of line segments that are currently intersected by the ray. In addition, these line segments are sorted by the distance to the origin. When the sweep line passes through an enpoint of a line segment, it either adds this line segment to the state (in case of a start vertex) or removes it from the state (in case of an end vertex). Whenever the nearest line segment changes, we update vertices of the visibility polygon accordingly.

API

All functions and classes are in the geometry namespace.

Visibility Polygon

Main function of the library is the visibility_polygon function. It takes observer's position and begin and end iterator of the line segment list (obstacle list) as its arguments. It computes vertices of a visibility polygon in CW order and returns them.

Preconditions:

  • The line segments must not intersect except at their endpoints
  • The visiblity polygon has to be closed.

Behaviour of the library is undefined if the preconditions aren't met. The first condition can be met by finding all intersection points of line segments and splitting them up. The second condition can be met by adding line segments of the bounding box of all obstacles. Note: checking these conditions is entirely up you. This library does not check them as that would introduce additional overhead.

Vector

The program implements a 2D vector template in the vector2.hpp header. You can use immutable operators +, -, *, / as well as their mutable variants. Apart from that you can use global functions dot(a, b) (calculates a dot product of 2 vectors), length_squared(vector), distance_squared(a, b), normal(a) (calculates a 2D orthogonal vector), cross(a, b) (determinat of the [[a_x, b_x], [a_y, b_y]] matrix). Floating point vectors can be normalized to have an unit length using the normalize(vector) function (it returns 0 vector in case of a 0 vector).

Primitives

All primitive objects that are used, are defined in the primitives.hpp header. It defines line_segment and ray types as well as a healper function compute_orientation that returns orientation of 3 points in a plane (left_turn, right_turn or collinear).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].