You are on page 1of 4
e106 Algarityn or Visibility Graphs An O(? log n) Algorithm for Computing Visibility Graphs ‘Our naive algorithm checks for intersection for all pairs of vertices against all obstacles edges. However, there will be ‘economy if we check for intersection in a certain order. In this algorithm, we check ifother vertices are visible to a vertex by their cyclic order around that vertex. The best way to illustrate this algorithm will be to give an example of the execution for a certain vertex. Step 1 : For a certain point p, sort all obstacle vertices according to he clockwise angle that the half-line from p to each obstacle vertex makes with the positive x-axis. vo Let the sorted list be w, .... w,. This is shown in the diagram above. This step takesO(n log n). Step 2 : Let P be the half line parallel to the positive x-axis starting at p. Find the obstacle edges, ¢,, that are properly intersected by P, and store them in a balanced search tree T (shown right below) in the order in which they are intersected by P. This step takes O(n). ei & wo Step 3 : for all vertices w; where i= 1 10 n if VISIBLE (w;) then Add w; to the list of visbilty edges Insert info T the obstacle edges incident to w; that lie on the clockwise side of the half-line ftom p to w; Delete from 7 the obstacle edges incident to w; on the counterclockwise side of the half line from p 0 w; VISIBLE(wi), 1. _ iftpwi intersects the interior of the obstacle of which w; isa vertex then return false 2. else if7=1 or w; is not on the segment pw; then Search in T for the edge ¢ in the lefimost left (the edge pintersects first) apes smith ed streinu/Teaching/Cawses/274/SpringG@ProjectPrilinplg Viiilyhim 1“ e106 Algarityn or Visibility Graphs 3 4 if ¢ exists and pwi intersects e then return false 5. else return true 6 else if w;.; is not visible 9 then return false 8 else Search in 7 for an edge ¢ that intersects w;_) 9 iffe exists then return false 10 else return true (the above pseudocode is taken directly from M. deBerg et al, Computational Geometry: algorithms and applications, 1997.) The consequences of this step on w is that lines 2-4 of VISIBLE gets executed because i= 1 and ¢; in T interseets pw. wis not visible fiom p. This step takes O(log n) time because of search on the binary tree. ef, 13, Moreover, edges e3 and ey , which are incident to wand lie on the clockwise side ofthe halE line from p to w , are added to T. Note that the edges now stored in T are the edges that will possibly intersect pw’, ‘We now tum to wz, The consequences of this step on w7 is that lines 2-4 gets executed because w is not on the segment pw’, and that pw intersects ey. wy is not visible ftom p. apes smith ed streinu/Teaching/Cawses/274/SpringG@ProjectPrilinplg Viiilyhim 24 e106 Algarityn or Visibility Graphs von, Edges es and es, which are incident to w, and lie on the clockwise side of the half-line ftom p to w, are added to T. Note that the edges now stored in Tare the edges that will possibly intersect pw. At w3, something interesting happens, e and e3, which are incident to wy on the counterclockwise side of the half line fiom p to ws, are deleted fiom 7, the binary tree, wn) wo This is a crucial step. The deletion of eg and e3 from the tree means that they will not be considered for intersection anymore in subsequent searches. The edges stored in T during the rm of pw. are the edges that will possibly ineresect pw;. This deletion, together withthe fit that the possibly intersecting edges are stored in a binary search tree, gives us reduction in time complexity. Similarly, at w4, eg is deleted ftom 7 while e7 is inserted into T vn) wo This algorithm goes on until all the run for w 7a has finished. This algorithm allows the storage of the obstacle apes smith ed streinu/Teaching/Cawses/274/SpringG@ProjectPrilinplg Viiilyhim a4 e106 Algarityn or Visibility Graphs ‘edges that will possibly intersect the next pw; pair. It therefore does not search for all obstacle edges unneci sarily Moreover, these edges are stored in a binary search tree, so even ifall obstacle edges are potential candidates, searching for one that does intersect will only cost O(log n). Lines 6-10 of VISIBLE deals with special cases when w;. ison the segment pwi, that is, p, w;.) and w; are collinear. I do not intend to go into the details, which can be found in M. deBerg et al, 1997. My purpose here to convince you that this algorithm runs in O(n? log n) time. The most time-consuming step in the rum for each vertex p is the sorting of obstacle vertices around p by angularity, which takes O(n log n). Since we repeat allthis process for each ofn vertex of the set of obstackes, the ‘overall runtime is O(n? logy). apes smith ed streinu/Teaching/Cawses/274/SpringG@ProjectPrilinplg Viiilyhim 4s

You might also like