To collect a round of cells, CircularTrip starts from the cell that is intersected by the given circle and lies left to . CircularTrip starts checking the cells along the circle in direction which is initially set as up. In order to make a clock-wise trip, the needs to be changed from up to right to down to left to up. The direction always holds the next direction of .
Without loss of generality, consider cell intersected by the circle which locates in the upper-left quadrant as shown in Fig. . The key fact is that the next cell intersected by the circle (i.e., the cell in which the arc is connected to one in ) is the adjacent cell either above (i.e., the cell that is next cell in direction ) or right to (i.e., the that is next cell in direction ). This is because the outgoing circle crosses either the upper boundary or the right boundary of . These two adjacent cells, and , are called candidate adjacent cells of . To collect the next cell intersected by the circle, CircularTrip only needs to examine one of the candidate adjacent cells (i.e; check its with the given radius ).
Algorithm presents the implementation of CircularTrip algorithm. Though any cell can be selected as but in our implementation the left most cell of the round (as shown in Fig. ) is selected. CircularTrip examines the cells clockwise along the given circle until is encountered again. When the currently being examined cell is at the maximum level in , the directions to find its candidate adjacent cells are updated accordingly (i.e., line 10 - 12). The cells when the directions and are changed are shown dark shaded in Fig. . Moreover, for some of the cells, and the are shown with solid and hollow arrows, respectively.
Lemma 1
The total cost of CircularTrip to collect a round of cells is to compute of cells, where is the number of cells in round .
Proof
Let be the current cell being examined and and be the cells next to in direction and , respectively. In order to prove Lemma , it is sufficient to prove that algorithm needs to compute of only one of or from in order to confirm the next intersected cell.
As can be seen from Fig. , selection of and is made so that following two conditions hold.
equation 1:
equation 2:
As cell
intersects the circle, it satisfies that
equation 3:
From equations 1,2 and 3, it can
be concluded that
equation 4:
CircularTrip computes
, and if
, then
intersects the
circle as can be inferred in conjunction with equation 4 that
.
If , then it infers that because . So CircularTrip can confirm as next intersected cell without computing its distance from because for cell in conjunction with equation 4, it is confirmed that .
Muhammad Aamir Cheema 2007-10-11