1

I need a fast algorithm to find the convex hull of large simple closed polygons.

The algorithm of Lee (as described in here, Section 2.1) is fine in most, but not all cases. For instance, the clockwise polygon (3,3)-(1,2)-(2,1)-(2,2)-(3,0)-(0,1)-(0,3)-(3,3) will be given the solution (3,3)-(2,1)-(0,1)-(0,3)-(3,3) -- which does not include all vertices.

The error is that (2,2) is put on the stack. I can't see how to modify Lee's algorithm to correct for this. Can you?

Of course I could instead use Melkman's algorithm, but Lee's takes advantage of my conditions, making it so much simpler and faster that I, if possible, would prefer it. Also, I am astonished that Lee's algorithm in the literature is said to be correct.

Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
PAF
  • 23
  • 4
  • Lee's algorithm is OK. Show your implementation. – n. m. could be an AI Oct 29 '16 at 07:44
  • Thanks for your comment! For Lee's algorithm I used this code (which did not work correctly in all circumstances): – PAF Oct 29 '16 at 16:19
  • Which code? There's no link. – n. m. could be an AI Oct 29 '16 at 19:06
  • Sorry, not used to submitting code on this site. Does it work this way? [C:\Users\Admin\Desktop\Convex hull.cpp] – PAF Oct 29 '16 at 20:20
  • The last function -- where I made a time and memory saving implemention of Melkman's algorithm, always works fine. – PAF Oct 29 '16 at 20:24
  • https://www.dropbox.com/s/qmaqciq16tm1t2f/Convex%20hull.cpp?dl=0 – PAF Oct 29 '16 at 20:35
  • Hmm I'm not sure it's the right algorithm. Preparata and Shamos have a very different version of Lee's algorithm and it makes more sense to me. You can find it on [google books](https://books.google.co.il/books?id=_p3eBwAAQBAJ&lpg=PA167&ots=BaYxv429gW&dq=%22lee's%20algorithm%22%20%22convex%20hull%22%20%22polygon%22&pg=PA166#v=onepage&q=%22lee's%20algorithm%22%20%22convex%20hull%22%20%22polygon%22&f=false) – n. m. could be an AI Oct 29 '16 at 21:50
  • I may have used a bad description of Lee's algorithm. Thank you for a better reference! – PAF Oct 30 '16 at 07:55
  • @PAF: I know this is an old post. Anyway, I was working on Melkman's algorithm and spotted a serious flaw that is found in most implementations: the first three vertices musn't be aligned, otherwise the iterations go wild. The cure is to skip aligned vertices in the initialization. This may look like a rare, unimportant case, but when the polygon is a path from a digital image it is the rule rather than the exception ! –  Oct 26 '17 at 21:03
  • Thank you! In my application alignment is very rare / should not occur, but I will include code to handle it just in case. – PAF Oct 31 '17 at 17:47

0 Answers0