Visibility polygon

Last updated
Visibility polygon shown in yellow. Four obstacles are shown in blue. Visibility polygon.svg
Visibility polygon shown in yellow. Four obstacles are shown in blue.

In computational geometry, the visibility polygon or visibility region for a point p in the plane among obstacles is the possibly unbounded polygonal region of all points of the plane visible from p. The visibility polygon can also be defined for visibility from a segment, or a polygon. Visibility polygons are useful in robotics, video games, and in determining positions to locate facilities, such as the best placement of security guards in an art gallery.

Contents

If the visibility polygon is bounded then it is a star-shaped polygon. A visibility polygon is bounded if all rays shooting from the point eventually terminate in some obstacle. This is the case, e.g., if the obstacles are the edges of a simple polygon and p is inside the polygon. In the latter case the visibility polygon may be found in linear time. [1] [2] [3] [4]

Definitions

Formally, we can define the planar visibility polygon problem as such. Let be a set of obstacles (either segments, or polygons) in . Let be a point in that is not within an obstacle. Then, the point visibility polygon is the set of points in , such that for every point in , the segment does not intersect any obstacle in .

Likewise, the segment visibility polygon or edge visibility polygon is the portion visible to any point along a line segment.

Applications

Visibility polygons are useful in robotics. For example, in robot localization, a robot using sensors such as a lidar will detect obstacles that it can see, which is similar to a visibility polygon. [5]

They are also useful in video games, with numerous online tutorials explaining simple algorithms for implementing it. [6] [7] [8]

Algorithms for point visibility polygons

Numerous algorithms have been proposed for computing the point visibility polygon. For different variants of the problem (e.g. different types of obstacles), algorithms vary in time complexity.

Naive algorithms

Naive algorithms are easy to understand and implement, but they are not optimal, since they can be much slower than other algorithms.

Uniform ray casting "physical" algorithm

In real life, a glowing point illuminates the region visible to it because it emits light in every direction. This can be simulated by shooting rays in many directions. Suppose that the point is and the set of obstacles is . Then, the pseudocode may be expressed in the following way:

algorithm naive_bad_algorithm(, ) is := for:         // shoot a ray with angle  := for each obstacle in :              := min(, distance from  to the obstacle in this direction)         add vertex  to return

Now, if it were possible to try all the infinitely many angles, the result would be correct. Unfortunately, it is impossible to really try every single direction due to the limitations of computers. An approximation can be created by casting many, say, 50 rays spaced uniformly apart. However, this is not an exact solution, since small obstacles might be missed by two adjacent rays entirely. Furthermore, it is very slow, since one may have to shoot many rays to gain a roughly similar solution, and the output visibility polygon may have many more vertices in it than necessary.

Ray casting to every vertex

The previously described algorithm can be significantly improved in both speed and correctness by making the observation that it suffices to only shoot rays to every obstacle's vertices. This is because any bends or corners along the boundary of a visibility polygon must be due to some corner (i.e. a vertex) in an obstacle.

algorithm naive_better_algorithm(, ) is := for each obstacle  in :         for each vertex  of :             // shoot a ray from  to  := distance from  to  := angle of  with respect to for each obstacle  in :                  := min(, distance from  to )             add vertex  to return

The above algorithm may not be correct. See the discussion under Talk.

The time complexity of this algorithm is . This is because the algorithm shoots a ray to every one of the vertices, and to check where the ray ends, it has to check for intersection with every one of the obstacles. This is sufficient for many simple applications such as video games, and as such many online tutorials teach this method. [8] However, as we shall see later, there are faster algorithms (or even faster ones if the obstacle is a simple polygon or if there are a fixed number of polygonal holes).

Optimal algorithms for a point in a simple polygon

A visibility polygon for a point in the center (shown in white) inside a simple polygon, outlined in black. Visibility polygon for a point in a simple polygon 2.svg
A visibility polygon for a point in the center (shown in white) inside a simple polygon, outlined in black.

Given a simple polygon and a point , a linear time algorithm is optimal for computing the region in that is visible from . Such an algorithm was first proposed in 1981. [2] However, it is quite complicated. In 1983, a conceptually simpler algorithm was proposed, [3] which had a minor error that was corrected in 1987. [4]

The latter algorithm will be briefly explained here. It simply walks around the boundary of the polygon , processing the vertices in the order in which they appear, while maintaining a stack of vertices where is the top of the stack. The stack constitutes the vertices encountered so far which are visible to . If, later during the execution of the algorithm, some new vertices are encountered that obscure part of , then the obscured vertices in will be popped from the stack. By the time the algorithm terminates, will consist of all the visible vertices, i.e. the desired visibility polygon. An efficient implementation was published in 2014. [9]

Optimal algorithms for a point in a polygon with holes

For a point in a polygon with holes and vertices in total, it can be shown that in the worst case, a algorithm is optimal. Such an algorithm was proposed in 1995 together with its proof of optimality. [10] However, it relies on the linear time polygon triangulation algorithm by Chazelle, which is extremely complex.

Optimal algorithms for a point among segments

Segments that do not intersect except at their endpoints

A visibility polygon for a point in the center (shown in white) amongst a set of arbitrary line segments in the plane, allowed to intersect only at their endpoints, acting as obstacles (shown in black). Visibility polygon for a point among segments.svg
A visibility polygon for a point in the center (shown in white) amongst a set of arbitrary line segments in the plane, allowed to intersect only at their endpoints, acting as obstacles (shown in black).

For a point among a set of segments that do not intersect except at their endpoints, it can be shown that in the worst case, a algorithm is optimal. This is because a visibility polygon algorithm must output the vertices of the visibility polygon in sorted order, hence the problem of sorting can be reduced to computing a visibility polygon. [11]

Notice that any algorithm that computes a visibility polygon for a point among segments can be used to compute a visibility polygon for all other kinds of polygonal obstacles, since any polygon can be decomposed into segments.

Divide and conquer

A divide-and-conquer algorithm to compute the visibility polygon was proposed in 1987. [12]

Angular sweep

An angular sweep, i.e. rotational plane sweep algorithm to compute the visibility polygon was proposed in 1985 [13] and 1986. [11] The idea is to first sort all the segment endpoints by polar angle, and then iterate over them in that order. During the iteration, the event line is maintained as a heap. An efficient implementation was published in 2014. [9]

Generally intersecting segments

For a point among generally intersecting segments, the visibility polygon problem is reducible, in linear time, to the lower envelope problem. By the Davenport–Schinzel argument, the lower envelope in the worst case has number of vertices, where is the inverse Ackermann function. A worst case optimal divide-and-conquer algorithm running in time was created by John Hershberger in 1989. [14]

Related Research Articles

In geometry, a polygon is a plane figure that is described by a finite number of straight line segments connected to form a closed polygonal chain or polygonal circuit. The solid plane region, the bounding circuit, or the two together, may be called a polygon.

Convex hull The smallest convex set containing a given set

In geometry, the convex hull or convex envelope or convex closure of a shape is the smallest convex set that contains it. The convex hull may be defined either as the intersection of all convex sets containing a given subset of a Euclidean space, or equivalently as the set of all convex combinations of points in the subset. For a bounded subset of the plane, the convex hull may be visualized as the shape enclosed by a rubber band stretched around the subset.

Dijkstras algorithm Graph search algorithm

Dijkstra's algorithm is an algorithm for finding the shortest paths between nodes in a graph, which may represent, for example, road networks. It was conceived by computer scientist Edsger W. Dijkstra in 1956 and published three years later.

In computer science, the Floyd–Warshall algorithm is an algorithm for finding shortest paths in a directed weighted graph with positive or negative edge weights. A single execution of the algorithm will find the lengths of shortest paths between all pairs of vertices. Although it does not return details of the paths themselves, it is possible to reconstruct the paths with simple modifications to the algorithm. Versions of the algorithm can also be used for finding the transitive closure of a relation , or widest paths between all pairs of vertices in a weighted graph.

Graph coloring Assignment of colors to elements of a graph subject to certain constraints.

In graph theory, graph coloring is a special case of graph labeling; it is an assignment of labels traditionally called "colors" to elements of a graph subject to certain constraints. In its simplest form, it is a way of coloring the vertices of a graph such that no two adjacent vertices are of the same color; this is called a vertex coloring. Similarly, an edge coloring assigns a color to each edge so that no two adjacent edges are of the same color, and a face coloring of a planar graph assigns a color to each face or region so that no two faces that share a boundary have the same color.

The point location problem is a fundamental topic of computational geometry. It finds applications in areas that deal with processing geometrical data: computer graphics, geographic information systems (GIS), motion planning, and computer aided design (CAD).

The set cover problem is a classical question in combinatorics, computer science, operations research, and complexity theory. It is one of Karp's 21 NP-complete problems shown to be NP-complete in 1972.

Point-set triangulation

A triangulation of a set of points in the Euclidean space is a simplicial complex that covers the convex hull of , and whose vertices belong to . In the plane, triangulations are made up of triangles, together with their edges and vertices. Some authors require that all the points of are vertices of its triangulations. In this case, a triangulation of a set of points in the plane can alternatively be defined as a maximal set of non-crossing edges between points of . In the plane, triangulations are special cases of planar straight-line graphs.

The art gallery problem or museum problem is a well-studied visibility problem in computational geometry. It originates from a real-world problem of guarding an art gallery with the minimum number of guards who together can observe the whole gallery. In the geometric version of the problem, the layout of the art gallery is represented by a simple polygon and each guard is represented by a point in the polygon. A set of points is said to guard a polygon if, for every point in the polygon, there is some such that the line segment between and does not leave the polygon.

In computational geometry, the Theta graph, or -graph, is a type of geometric spanner similar to a Yao graph. The basic method of construction involves partitioning the space around each vertex into a set of cones, which themselves partition the remaining vertices of the graph. Like Yao Graphs, a -graph contains at most one edge per cone; where they differ is how that edge is selected. Whereas Yao Graphs will select the nearest vertex according to the metric space of the graph, the -graph defines a fixed ray contained within each cone and selects the nearest neighbor with respect to orthogonal projections to that ray. The resulting graph exhibits several good spanner properties.

In statistics, M-estimators are a broad class of extremum estimators for which the objective function is a sample average. Both non-linear least squares and maximum likelihood estimation are special cases of M-estimators. The definition of M-estimators was motivated by robust statistics, which contributed new types of M-estimators. The statistical procedure of evaluating an M-estimator on a data set is called M-estimation. 48 samples of robust M-estimators can be founded in a recent review study.

In computer science, the Hopcroft–Karp algorithm is an algorithm that takes as input a bipartite graph and produces as output a maximum cardinality matching – a set of as many edges as possible with the property that no two edges share an endpoint. It runs in time in the worst case, where is set of edges in the graph, is set of vertices of the graph, and it is assumed that . In the case of dense graphs the time bound becomes , and for sparse random graphs it runs in time with high probability.

Algorithms that construct convex hulls of various objects have a broad range of applications in mathematics and computer science.

A geometric spanner or a t-spanner graph or a t-spanner was initially introduced as a weighted graph over a set of points as its vertices for which there is a t-path between any pair of vertices for a fixed parameter t. A t-path is defined as a path through the graph with weight at most t times the spatial distance between its endpoints. The parameter t is called the stretch factor or dilation factor of the spanner.

Polygonal chain

In geometry, a polygonal chain is a connected series of line segments. More formally, a polygonal chain P is a curve specified by a sequence of points called its vertices. The curve itself consists of the line segments connecting the consecutive vertices.

In computational geometry, a constrained Delaunay triangulation is a generalization of the Delaunay triangulation that forces certain required segments into the triangulation as edges, unlike the Delaunay triangulation itself which is based purely on the position of a given set of vertices without regard to how they should be connected by edges. It can be computed efficiently and has applications in geographic information systems and in mesh generation.

Top tree

A top tree is a data structure based on a binary tree for unrooted dynamic trees that is used mainly for various path-related operations. It allows simple divide-and-conquer algorithms. It has since been augmented to maintain dynamically various properties of a tree such as diameter, center and median.

In mathematics a translation surface is a surface obtained from identifying the sides of a polygon in the Euclidean plane by translations. An equivalent definition is a Riemann surface together with a holomorphic 1-form.

John E. Hershberger is an American computer scientist and software professional, a principal engineer at Mentor Graphics Corporation since 1993. He is known for his research in computational geometry and algorithm engineering.

A partition of a polygon is a set of primitive units, which do not overlap and whose union equals the polygon. A polygon partition problem is a problem of finding a partition which is minimal in some sense, for example a partition with a smallest number of units or with units of smallest total side-length.

References

  1. Franco P. Preparata and Michael Ian Shamos (1985). Computational Geometry - An Introduction. Springer-Verlag. 1st edition: ISBN   0-387-96131-3; 2nd printing, corrected and expanded, 1988: ISBN   3-540-96131-3; Russian translation, 1989: ISBN   5-03-001041-6.
  2. 1 2 El Gindy, Hossam; Avis, David (1981). "A linear algorithm for computing the visibility polygon from a point". Journal of Algorithms. 2 (2): 186–197. doi:10.1016/0196-6774(81)90019-5.
  3. 1 2 Lee, D. T. (May 1983). "Visibility of a simple polygon". Computer Vision, Graphics, and Image Processing. 22 (2): 207–221. doi:10.1016/0734-189X(83)90065-8.
  4. 1 2 Joe, Barry; Simpson, R. B. (1987). "Corrections to Lee's visibility polygon algorithm". BIT Numerical Mathematics. 27 (4): 458–473. doi:10.1007/BF01937271.
  5. Guibas, Leonidas; Motwani, Rajeev; Raghavan, Prabhakar (1992). The robot localization problem in two dimensions. ACM-SIAM symposium on Discrete algorithms. Society for Industrial and Applied Mathematics.
  6. Liow, Nicklaus. "SIGHT & LIGHT how to create 2D visibility/shadow effects for your game" . Retrieved 9 May 2014.
  7. Patel, Amit (5 July 2012). "2d Visibility Algorithm" . Retrieved 9 May 2014.
  8. 1 2 Patel, Amit (5 July 2012). "Blobs in Games: 2d Visibility" . Retrieved 9 May 2014.
  9. 1 2 Bungiu, Francisc; Hemmer, Michael; Hershberger, John; Huang, Kan; Kröller, Alexander (2014). "Efficient Computation of Visibility Polygons". arXiv: 1403.3905 [cs.CG].
  10. Heffernan, Paul; Mitchell, Joseph (1995). "An optimal algorithm for computing visibility in the plane" (PDF). SIAM Journal on Computing. 24 (1): 184–201. doi:10.1137/S0097539791221505. hdl: 1813/8838 .
  11. 1 2 Suri, Subhash; O'Rourke, Joseph (1986). Worst-case optimal algorithms for constructing visibility polygons with holes. Symposium on Computational geometry. ACM. pp. 14–23. doi:10.1145/10515.10517.
  12. Arkin, E.; Mitchell, Joseph (1987). An optimal visibility algorithm for a simple polygon with star-shaped holes (Technical report). Cornell University Operations Research and Industrial Engineering. 746.
  13. Asano, Tetsuo (1985). An efficient algorithm for finding the visibility polygon for a polygonal region with holes. Institute of Electronics, Information, and Communication Engineers. 68. pp. 557–559.
  14. Hershberger, John (1989). "Finding the upper envelope of line segments in time". Information Processing Letters. 33 (4): 169–174. doi:10.1016/0020-0190(89)90136-1.

Software