Need to solve this problem. We have a polar coordinate system and an array of points, we need to combine these points into a sector and display it. Everything is simple, we take the minimum and maximum values and draw a sector between them. But what is the problem, it will never pass through zero. The sector will either be from zero to zero. Accordingly, this sector is not correct (not flexible).
1 answer
I would use about this algorithm. Angles in degrees. The code is sketchy.
list.sort(); int size = list.size(); for (int i=0;i<size;i++) list.add(list[i] + 360); int bestDeg= list[size-1] - list[0]; int left = list[0]; int reigth = list[size-1]; for (int i=1; i<size;i++) if (bestDeg > list[size-1+i] - list[i]){ bestDeg = list[size-1+i] - list[i]; left = list[i]; reigth = list[size-1+i]; }
|