Блог пользователя snorkel

Автор snorkel, история, 4 года назад, По-английски

I have polygon and its vertices represented with randomly shuffled 2d points, how can I find the correct order?

In correct order I mean order so that segment between P[i] and P[(i + 1) % n] is a side of polygon.

Or if this is hard, how to solve it for 4 sides?

I'm looking for an efficient solutions. Many thanks.

  • Проголосовать: нравится
  • +4
  • Проголосовать: не нравится

»
4 года назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

You can find the upper hull of the points, add it to the list, then add the points sorted by their x coordinates (lower points first)

»
4 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Is the polygon guaranteed to be convex?

»
4 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

wouldn't it be the right thing to do,to simply sort them in clockwise direction, using the formula of cos between 2 vectors,however,you have to fing the center of that polygon to form the vectors