A New Optimal Algorithm for Computing the Visibility Area of a simple Polygon from a Viewpoint
Hamid Hoorfar Alireza Bagheri

QuipuNet: convolutional neural network for single-molecule nanopore sensing
    Ulrich F. Keyser
    December 30, 2023
===========================================================================

 
Given a simple polygon 𝒫 of n vertices in the Plane. We study the problem of computing the visibility area from a given viewpoint q inside 𝒫 where only sub-linear variables are allowed for working space.
Without any memory-constrained, this problem was previously solved in O(n)-time and O(n)-variables space. In a newer research, the visibility area of a point be computed in 
O(n)-time, using O(√(n)) variables for working space. In this paper, we present an optimal-time algorithm, using O(c/log n) variables space for computing visibility area, where c<n is the number of critical vertices.
We keep the algorithm in the linear-time and reduce space as much as possible.

Keywords: Visibility Area, Constant-Memory Model, Memory-constrained Algorithm, Streaming Algorithm, Guarding Polygon.




§ INTRODUCTION

The visibility area of a simple polygon 𝒫 from an internal viewpoint q is the set of all points of 𝒫 that are visible from q, since two points p and q are visible from each other whenever the line-segment pq does not intersects 𝒫 in more than one connected component i.e. the visibility area of viewpoint q inside 𝒫 is the set of all points in 𝒫 that are visible from q. In similar definition, we say that the points p and q inside 𝒫 are k-visible from each others if the line segment pq intersects the boundary of 𝒫 at most in k times. The k-visibility area of viewpoint q inside 𝒫 is the set of all points in 𝒫 that are k-visible from q.
One of the important problem studies in computational geometry is visibility <cit.>. Joe and Simpson presented the first correct optimal algorithm for computing visibility area (region) from a point in linear-time and linear-space <cit.>. In constrained-memory model, some algorithms has restricted memory (generally, not more than logarithmic in the size of input and typically constant). In constant-memory, algorithms do not have a long-term memory structure. Processing and deciding of current data must be at the moment. Using constant space, there is not enough memory for storing previously seen data or even for the index of this data. However, in the constraint-memory mode, there is O(s) bits working space during running algorithm, certainly, less than  O(n). Several researchers worked on constrained-memory algorithms in visibility <cit.>. Some recent related works are reviewed here. Computing visibility area of a viewpoint q in the simple polygon 𝒫 with extra  O(1) variables (O(log n) bits per variable) has time-complexity of O(nr) where r is the cardinality of the reflex vertices of 𝒫 in the output  <cit.> while there exists a linear-time algorithm for computing the visibility area without constrained memory, using O(n) variables <cit.>. If there is O(s) variables for the computing, the time complexity of computing visibility area decreases to O(nr/2^s+n logr) where s ∈ O(logr). It was presented a time-space trade-off algorithm which reports the k-visibility area for q  ∈𝒫 in O(cn/s + n log s + min{kn/s, n loglog_s n}) time, the algorithm uses O(s) words with O(log n) bits each of workspace and c ≤ n is the number of vertices of 𝒫 where the visibility area changes for the viewpoint q <cit.>. If k=1 and s=1, their algorithm time complexity is O(cn), in fact, using O(log n) bits space. Also, it is presented a linear-time algorithm for computing visibility area, using O(√(n)) variables <cit.>.

Our General Result:

We provide an optimal-time algorithm of O(n) time, and O(c+log n) bits space (or O(c/log n) variables of O(log n) bits each) for computing visibility area of a viewpoint q inside 𝒫, where c is the number of critical vertices in 𝒫. Also, c≤ r<n, where r is the number of reflex vertices of 𝒫. We keep the algorithm linear-time and reduce space as much as possible.


§ PRELIMINARIES


We present our algorithm in the sub-linear space. Assume that a simple polygon 𝒫 is given in a read-only array 𝒜 of n vertices (each element is wrote in log(n) bits) in counterclockwise order along the boundary and there is a read-only variable that is contained a query viewpoint q inside 𝒫, also, it has log(n) bits. It is called input with random access. We can use O(s) writable and readable variables of size O(log n) as workspace of the algorithm. The workspace is both writable and readable during the running of the algorithm. In this model, the output is available in a write-only array that will contain the boundary of visibility area of q in counterclockwise order, at the end of the process. 

For every vertex p_i of 𝒫, we compute the angle between vector(ray) qp_i and the positive X-axis as denoted by θ_i (radian). For every θ_i, where i between 0 and n-1, 0≤θ_i≤ 2π. If p_i is a vertex, then ρ_i equals the length of qp_i.
For every 3 vertices v_1,v_2 and v_3, the angle ∠v_1v_2v_3 is called counterclockwise turn, if and only if v_3 is placed on the left side of the vector v_1v_2, otherwise, if and only if v_3 is placed on the right side, it is called clockwise turn, see Figure <ref>. Sometimes, for simplicity we denote angle ∠v_1v_2v_3 as ∠v_2. For two vertices ν and ν', let Γ_ν is the line which is contained ν and q, let e_1 and e_2 are two edges which are contained ν', so, the intersection of e_1 and Γ_ν, or e_2 and Γ_ν, that one touches the polygon from internal of 𝒫(from direction of q), is called shadow of ν, we denote it by S(ν) or ν, see Figure <ref>(A) and <ref>(B).

If θ_c-1<θ_c >θ_c+1 and ∠ p_c is a clockwise turn, then p_c is called critical-max vertex and if θ_c-1>θ_c <θ_c+1 and ∠ p_c is a counterclockwise turn, then p_c is called critical-min vertex. If a vertex is critical-max or critical-min, it is called critical.



§ AN ALGORITHM FOR FINDING EFFECTIVE CRITICAL VERTICES OF SIMPLE POLYGONS

In this section, the aim is presenting a linear-time algorithm for finding effective critical vertices of 𝒫 in the sub-linear space model. The effective critical vertex is a critical vertex that is visible from q. We use O(c+log n) bits for working space of our algorithm to marking positions of effective critical vertices among all critical vertices of 𝒫 where c<n is the number of critical vertices, therefore, variable i in Algorithm <ref> is an index for the critical vertices. This workspace equals to O(c/log n) variables that have log n bits each. Assume array W with r bits is a part of the algorithm workspace and we can also use a constant number of variables during computing. If k-th bit of W (denoted by w_k) is 1, then it means the k-th critical vertex of the boundary is visible from q (effective), else the k-th critical vertex of the boundary is not effective. Using array W, we can save the position of effective critical vertices among all critical vertices. In the following, we will explain how our algorithm works.

At the first, all elements of W have been set to 1. We traverse among the boundary in both directions, clockwise and counterclockwise order. If the edges of a vertex (generally, critical vertex) causes j-th critical vertex not to be visible from q, we set w_j=0 that means it is not effective. See Algorithm <ref>.


After running Algorithm <ref>, the angles sequence of critical-min vertices ordered counterclockwise will be ascending. Also, the angles sequence of critical-max vertices ordered counterclockwise will be ascending, too. The running of this algorithm may not lead to the angles sequence of all critical vertices is ascending, ordered counterclockwise. So, we use Algorithm <ref> to merge these two ascending sequences to obtain the sequence of all effective critical vertices.


Actually finding all effective critical vertices, is the most important work for computing visibility area of 𝒫 from viewpoint q. Now, if we face i-th critical vertex, we find whether it is in visibility area from q by looking at w_i∈ W.
For computing W, we do two procedures:

  
  * Finding critical vertices of 𝒫 that are not effective and providing remained critical-min and critical-max vertices in ascending order, separately in two sequence, in the linear-time using O(c+log n) bits space.
  
  * Merge two above sequences and computing all effective critical vertices in the linear-time, using same O(c+log n) bits space.

Now, we have the following theorem:

Given a simple polygon 𝒫 in a read-only array 𝒜 of n vertices O(log n) bits each and a viewpoint q inside 𝒫. Using O(c+log n) bits space (equal to O(c/log n) additional variables of workspace), there is an algorithm which computes all visible critical vertices in the linear-time, where c is the number of all critical vertices. See Algorithm <ref>,<ref> and Video <ref> <ref> to illumination.




§ AN ALGORITHM FOR COMPUTING VISIBILITY AREA OF SIMPLE POLYGONS

In this section, we assume that all c visible (effective) critical vertices of 𝒫 are reported in W. These vertices divide the boundary of 𝒫 into c separate chains. Let p_i and p_j are two consecutive effective critical vertices and the chain that is located between them is called Δ. If we provide a linear-time algorithm to computing visibility area of Δ from q (linear-time in the number of Δ), then computing visibility area of 𝒫 is computable in O(n)-time. See Figure <ref>.

So, we have assumed that p_i and p_j are the start and end points of Δ (i.e. let θ_i<θ_j), respectively. While p_i is not a critical-max and p_j is not a critical-min, we report Δ as the visibility area. If p_i is a critical-max, then we compute all the intersections between line passes from qp_i and every edge of Δ, and denote the nearest one by A, else we denote p_i by A. Similarly, if p_j is a critical-min, then we compute all the intersections between the line passes from qp_j and every edge of Δ, and denote the nearest one by B, else we denote p_j by B. After that, we report the boundary of visibility area as:


p_i, A, the vertices between A and B on chain Δ, B, p_j.


Now, we have our first main theorem in this section:

Given a simple chain Δ in a read-only array 𝒜 of m vertices O(log n) bits each and a viewpoint q in the plane. Using O(log n) bits space (equal to O(1) additional variables of workspace). If Δ has only two visible critical vertices, there is an algorithm which computes the visibility area of Δ in the linear-time. See Algorithm <ref> in Appendix <ref> and Video <ref>.

We run this algorithm for every two critical vertices marked in W. By doing it, the sequence of visibility area of 𝒫 will written in 𝒜', respectively i.e. we traverse on the boundary of 𝒫 counterclockwise until finding two consecutive visible critical vertices, using checking the bits of W. For example, let α_1 and α_2 are these two, so, we compute the visibility area of the chain between them by traverse the chain vertices. After that we continue traversing from α_2 to find next consecutive visible critical vertex, for example α_3, we compute the visibility area of new chain between α_2 and α_3 by traverse the chain vertices. This processing continues until we find all visibility area of 𝒫. Now, we have the following theorem:

Given a simple polygon 𝒫 with n vertices in a read-only array and a viewpoint q inside 𝒫. Using O(c/log n) variables or O(c+log n) bits of working space, there is an algorithm which computes visibility area of 𝒫 inside q in O(n) time. Where c is the number of critical vertices.





§ CONCLUSION

We studied the problem of computing visibility of a viewpoint inside a simple polygon. We used a sub-linear workspace for our presented algorithm and kept the time-complexity linear-time and optimal, but our algorithm is not the first one. We read our input from a read-only array and wrote our output in a write-only array. For working space, we used c bits where c was the number of critical vertices and a constant number of variables. The working space was both writable and readable. Every used variable has O(log n) bits of space. This number of bits (O(log n) bits) is required to store one index of the vertices, for example. So, the space-complexity of our algorithm is (c/log n) variables. Our aim was keeping time optimally and reducing space complexity. It will excepted to solve this problem with constant variables of workspace in the future work.

plain



§ APPENDICES




 §.§ List of Videos




The video is available at https://www.dropbox.com/s/1flvb04zscdwug2/Algorithm



The video is available at https://www.dropbox.com/s/wiykwcas78zi823/Algorithm



The video is available at https://www.dropbox.com/s/j0214sowyalhh63/Algorithm



 §.§ Additional Algorithms






