Visibility Polygon
   HOME

TheInfoList



OR:

In computational geometry, the visibility polygon or visibility region for a point in the plane among obstacles is the possibly unbounded polygonal region of all points of the plane visible from . The visibility polygon can also be defined for visibility from a segment, or a polygon. Visibility polygons are useful in
robotics Robotics is the interdisciplinary study and practice of the design, construction, operation, and use of robots. Within mechanical engineering, robotics is the design and construction of the physical structures of robots, while in computer s ...
,
video games A video game or computer game is an electronic game that involves interaction with a user interface or input device (such as a joystick, game controller, controller, computer keyboard, keyboard, or motion sensing device) to generate visual fe ...
, and in various optimization problems such as the facility location problem and the
art gallery problem The art gallery problem or museum problem is a well-studied visibility problem in computational geometry. It originates from the following real-world problem: "In an art gallery, what is the minimum number of guards who together can observe the ...
. If the visibility polygon is bounded then it is a
star-shaped polygon In geometry, a star-shaped polygon is a polygonal region in the plane that is a star domain, that is, a polygon that contains a point from which the entire polygon boundary is visible. Formally, a polygon is star-shaped if there exists a po ...
. 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 In geometry, a simple polygon is a polygon that does not Intersection (Euclidean geometry), intersect itself and has no holes. That is, it is a Piecewise linear curve, piecewise-linear Jordan curve consisting of finitely many line segments. The ...
and is inside the polygon. In the latter case the visibility polygon may be found in
linear time In theoretical computer science, the time complexity is the computational complexity that describes the amount of computer time it takes to run an algorithm. Time complexity is commonly estimated by counting the number of elementary operations ...
.


Definitions

Formally, we can define the planar visibility polygon problem as such. Let S be a set of obstacles (either segments, or polygons) in \mathbb^2. Let p be a point in \mathbb^2 that is not within an obstacle. Then, the ''point visibility polygon'' V is the set of points in \mathbb^2, such that for every point q in V, the segment pq does not intersect any obstacle in S. Likewise, the ''segment visibility polygon'' or ''edge visibility polygon'' is the portion visible to any point along a
line segment In geometry, a line segment is a part of a line (mathematics), straight line that is bounded by two distinct endpoints (its extreme points), and contains every Point (geometry), point on the line that is between its endpoints. It is a special c ...
.


Applications

Visibility polygons are useful in
robotics Robotics is the interdisciplinary study and practice of the design, construction, operation, and use of robots. Within mechanical engineering, robotics is the design and construction of the physical structures of robots, while in computer s ...
. For example, in
robot localization Robot localization denotes the robot's ability to establish its own position and orientation within the frame of reference. Path planning is effectively an extension of localization, in that it requires the determination of the robot's current pos ...
, a robot using sensors such as a
lidar Lidar (, also LIDAR, an acronym of "light detection and ranging" or "laser imaging, detection, and ranging") is a method for determining ranging, ranges by targeting an object or a surface with a laser and measuring the time for the reflected li ...
will detect obstacles that it can see, which is similar to a visibility polygon. They are also useful in
video games A video game or computer game is an electronic game that involves interaction with a user interface or input device (such as a joystick, game controller, controller, computer keyboard, keyboard, or motion sensing device) to generate visual fe ...
, with numerous online tutorials explaining simple algorithms for implementing it.


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 Mathematical optimization (alternatively spelled ''optimisation'') or mathematical programming is the selection of a best element, with regard to some criteria, from some set of available alternatives. It is generally divided into two subfiel ...
, 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 Light, visible light, or visible radiation is electromagnetic radiation that can be visual perception, perceived by the human eye. Visible light spans the visible spectrum and is usually defined as having wavelengths in the range of 400– ...
in every direction. This can be simulated by shooting rays in many directions. Suppose that the point is p and the set of obstacles is S. Then, the
pseudocode In computer science, pseudocode is a description of the steps in an algorithm using a mix of conventions of programming languages (like assignment operator, conditional operator, loop) with informal, usually self-explanatory, notation of actio ...
may be expressed in the following way: algorithm naive_bad_algorithm(p, S) is V := \emptyset for \theta = 0, \cdots, 2\pi: // shoot a ray with angle \theta r := \infty for each obstacle in S: r := min(r, distance from p to the obstacle in this direction) add vertex (\theta, r) to V return V 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(p, S) is V := \emptyset for each obstacle b in S: for each vertex v of b: // shoot a ray from p to v r := distance from p to v \theta := angle of v with respect to p for each obstacle b' in S: r := min(r, distance from p to b') add vertex (\theta, r) to V return V The above algorithm may not be correct. See the discussion under Talk. The time complexity of this algorithm is O(n^2). This is because the algorithm shoots a ray to every one of the n vertices, and to check where the ray ends, it has to check for intersection with every one of the O(n) obstacles. This is sufficient for many simple applications such as video games, and as such many online tutorials teach this method. However, as we shall see later, there are faster O(n\log n) 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

Given a simple polygon \mathcal and a point p, a
linear time In theoretical computer science, the time complexity is the computational complexity that describes the amount of computer time it takes to run an algorithm. Time complexity is commonly estimated by counting the number of elementary operations ...
algorithm is optimal for computing the region in \mathcal that is visible from p. Such an algorithm was first proposed in 1981. However, it is quite complicated. In 1983, a conceptually simpler algorithm was proposed, which had a minor error that was corrected in 1987. The latter algorithm will be briefly explained here. It simply walks around the boundary of the polygon \mathcal, processing the vertices in the order in which they appear, while maintaining a
stack Stack may refer to: Places * Stack Island, an island game reserve in Bass Strait, south-eastern Australia, in Tasmania’s Hunter Island Group * Blue Stack Mountains, in Co. Donegal, Ireland People * Stack (surname) (including a list of people ...
of vertices \mathcal=s_0, s_1,\cdots, s_t where s_t is the top of the stack. The stack constitutes the vertices encountered so far which are visible to p. If, later during the execution of the algorithm, some new vertices are encountered that obscure part of \mathcal, then the obscured vertices in \mathcal will be popped from the stack. By the time the algorithm terminates, \mathcal will consist of all the visible vertices, i.e. the desired visibility polygon. An efficient implementation was published in 2014.


Optimal algorithms for a point in a polygon with holes

For a point in a polygon with h holes and n vertices in total, it can be shown that in the worst case, a \Theta(n + h\log h) algorithm is optimal. Such an algorithm was proposed in 1995 together with its proof of optimality. However, it relies on the linear time
polygon triangulation In computational geometry, polygon triangulation is the partition of a polygonal area (simple polygon) into a set of triangles, i.e., finding a set of triangles with pairwise non-intersecting interiors whose union is . Triangulations may ...
algorithm by Chazelle, which is extremely complex.


Optimal algorithms for a point among segments


Segments that do not intersect except at their endpoints

For a point among a set of n segments that do not intersect except at their endpoints, it can be shown that in the worst case, a \Theta(n\log n) 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 Sorting refers to ordering data in an increasing or decreasing manner according to some linear relationship among the data items. # ordering: arranging items in a sequence ordered by some criterion; # categorizing: grouping items with similar p ...
can be reduced to computing a visibility polygon. 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 In computer science, divide and conquer is an algorithm design paradigm. A divide-and-conquer algorithm recursively breaks down a problem into two or more sub-problems of the same or related type, until these become simple enough to be solved dir ...
to compute the visibility polygon was proposed in 1987.


= Angular sweep

= An ''angular sweep'', i.e. rotational
plane sweep In computational geometry, a sweep line algorithm or plane sweep algorithm is an algorithmic paradigm that uses a conceptual ''sweep line'' or ''sweep surface'' to solve various problems in Euclidean space. It is one of the critical techniques i ...
algorithm to compute the visibility polygon was proposed in 1985 and 1986. 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.


Generally intersecting segments

For a point among generally intersecting segments, the visibility polygon problem is reducible, in linear time, to the
lower envelope In mathematics, the lower envelope or pointwise minimum of a finite set of functions is the pointwise minimum of the functions, the function whose value at every point is the minimum of the values of the functions in the given set. The concept of ...
problem. By the Davenport–Schinzel argument, the lower envelope in the worst case has \Theta(n\alpha(n)) number of vertices, where \alpha(n) is the
inverse Ackermann function In computability theory, the Ackermann function, named after Wilhelm Ackermann, is one of the simplest and earliest-discovered examples of a total computable function that is not primitive recursive. All primitive recursive functions are total ...
. A worst case optimal divide-and-conquer algorithm running in \Theta(n\log n) time was created by John Hershberger in 1989.{{cite journal , last = Hershberger , first = John , title = Finding the upper envelope of n line segments in O(n\log n) time , journal = Information Processing Letters , volume = 33 , number = 4 , year = 1989 , pages = 169–174 , doi=10.1016/0020-0190(89)90136-1


References


External links

* http://web.informatik.uni-bonn.de/I/GeomLab/VisPolygon/index.html.en (visibility in simple polygons - applets)


Software


VisiLibity
A free open source C++ library for visibility computations in planar polygonal environments.
visibility-polygon-js
A public domain Javascript library for computing a visibility polygon for a point among segments using the angular sweep method. Polygons Geometric algorithms