Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

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

Автор ivplay, история, 8 лет назад, По-английски

Given N points. I want to find convex hull keeping collinear points. How should I prepare my initial sort function so that I don't have to make a right turn for points who are collinear? Example: 6 1 1 3 0 2 0 4 1 2 2 0 0  Here is the image for those points. Now I want point F(2,2) comes before point C(1,1) also point B(2,0) comes before point D(3,0) I mean I want following order after sorting A,B,D,E,F,C. what should be my sorting criteria?

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

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

I don't know why that image is being failed to load. Anyway this is the link of the image: http://postimg.org/image/r8enk3er5/

»
8 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

I'm sure It's impossible to sort points in folowing order.If you add (2, 0.5) it will be a big question about order. I think the best idea is to find points using classical algorithm and then add points that lie between adjecent points on convex hull. It will take about O(n*n log n) using set, but i hope it can be solved with faster way.

  • »
    »
    8 лет назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    Well, actually it's possible to sort the points beforehand. If we sort the points by their angle and then by their distance from (0, 0) assuming that (0, 0) is the leftmost-bottom point from the set, then the order will be correct everywhere except for the last edge of the convex hull. That is the points on all edges of the convex hull except for the last one will be in the correct order and the points located on the last edge will be reversed. Notice that the last point in the sorted list will always belong to the convex hull which means we can just reverse the order of all points having the same angle as the last one (the one with the largest angle).

»
8 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

NVM