# Questions

Fragment of a discussion from User talk:Wompi

You nailed it mate. Thanks. Looks like i was totaly looking at the wrong direction. But at least my gut was right :). Man this is even smaller than i hoped for.

Wompi10:26, 24 April 2012

You are welcome, but this code would not work:) Now I have no time to describe why (writing on english is difficult for me), but try to test different cases and you will easy understand the problem.

Jdev05:50, 25 April 2012

I also thought there might be some issues at certain angles with the single loop approach.

I think you need to take a [itex]n^2[/itex] approach, ie, a loop within a loop. Otherwise you need to use a sorting technique (with nlogn), then a single loop. Here is pseudocode:

```initialise min_sum = Inf
For each bot, b:
me_b = find the angle from me to b
initialise min_rel = Inf, max_rel = -Inf.
for each bot c, excluding b:
me_c = find the angle from me to c
rel = the relative angle between me_b and me_c
if rel < min_rel, min_rel = rel. if rel > max_rel, max_rel = rel.
sum = max_rel - min_rel
if sum < min_sum, min_sum = sum, min_ang = me_b + min_rel, max_ang = me_b + max_rel.
```

The other approach would be to sort all the angles into radial order, then go through looking for the largest space between two angles, and then use the opposite part of the circle. So in pseudocode:

```for each bot, b:
me_b = angle from me to b
angles[i++] = me_b

sort_ascending(angles)

max_rel = abs(relative_angle(angles[0] - angles[angles.length - 1]))
min_angle = angles[0]
max_angle = angles[angles.length-1]
max_index = 0
for(i = 1; i < angles.length; i++)
rel = abs(relative_angles(angles[i-1] - angles[i]));
if rel > max_rel
max_rel = rel
min_angle = angles[i]
max_angle = angles[i-1]
max_index = i
```
Skilgannon08:35, 25 April 2012

Yes Jdev you are right it does not work for all angles and i was aware of that. But it pushed me into another direction to think about it. If the bot stays almost ever on the edge or corner of the battlefield your code works very well i get some really impressive average visit counts with my radar.

Thanks Skilgannon your first approach looks interesting and i will give it a try. Haven't found the time for now. My first thougth to overcome the angle glitch was to throw in a signum() direction check and switch the angles if they don't fit. Don't know how to describe this and its again more of my gut feeling which tells me that this might work. I'm almost sure i did this once but lost it. The second one looks a little like my first try, not really sure about that to.

But anyway, thanks to both of you for bringing me out of my stubborn mind state.

Wompi15:00, 25 April 2012